Skip to content

Commit 053e9c3

Browse files
[ docs2 - docs1 ] [ #12 ]merge request / from syedabdullahbukhari77/docs-d2
[ docs2 - docs1 ]--update: Add Excercises/Python Session Fundamentals/Python Session 02
2 parents 47f60ad + 93bd724 commit 053e9c3

File tree

2 files changed

+338
-0
lines changed

2 files changed

+338
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyMAQwk5Up4/TfwCoyql3Z8P"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"9etUWLtkGTe6","executionInfo":{"status":"ok","timestamp":1755620011945,"user_tz":-300,"elapsed":16,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"7c7bae76-f021-425d-df2c-538b9448bd36"},"outputs":[{"output_type":"stream","name":"stdout","text":["Not Prime\n"]}],"source":["number = 8\n","\n","is_prime = None\n","\n","if number <= 1: is_prime = False\n","else:\n"," for i in range(2, number):\n"," if number% i == 0: is_prime = False\n"," break\n","\n","print('Prime' if is_prime else\n"," 'Not Prime')"]},{"cell_type":"code","source":["number = 100\n","\n","is_prime = None\n","\n","if number <= 1: is_prime = False\n","\n","else:\n"," for i in range(2 , number):\n"," if number % i == 0:\n"," is_prime = True\n"," break\n","\n","if is_prime: print('Prime')\n","else: print('Not Prime')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"bahq1X66Guyt","executionInfo":{"status":"ok","timestamp":1755620198793,"user_tz":-300,"elapsed":52,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"fd3b70aa-b863-43d9-f1d2-e398647969a9"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Prime\n"]}]},{"cell_type":"code","source":["reversed_characters = ''"],"metadata":{"id":"kW-zTTrIHZpf"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["text: str = 'California'"],"metadata":{"id":"LZtre2BkH3BO"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["for element in text:\n"," reversed_characters = element + reversed_characters\n","print(reversed_characters)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"-h8U7HvRH95e","executionInfo":{"status":"ok","timestamp":1755620353659,"user_tz":-300,"elapsed":19,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"c05ae7e4-8cfa-458f-e8e4-6e23a3de8421"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["ainrofilaC\n"]}]},{"cell_type":"code","source":["numbers = [4, 1, 9, 3, 7]\n","max_numbers = numbers[0]"],"metadata":{"id":"pHKQ9e1FIFuH","executionInfo":{"status":"ok","timestamp":1755621810571,"user_tz":-300,"elapsed":5,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}}},"execution_count":15,"outputs":[]},{"cell_type":"code","source":["for num in numbers:\n"," if num > max_numbers :\n"," max_numbers = num\n","\n","print(f'max: is {max_numbers}')"],"metadata":{"id":"SY8Z_rCSMEXS","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1755621816794,"user_tz":-300,"elapsed":7,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"14b81e75-2c7d-4ca7-dd43-7f767268c7f2"},"execution_count":16,"outputs":[{"output_type":"stream","name":"stdout","text":["max: is 9\n"]}]},{"cell_type":"code","source":["for i in range(1,10):\n"," if i % 2 == 0: print('Is Even')\n"," else: print('Is Odd')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"Ocm0va5aNf1s","executionInfo":{"status":"ok","timestamp":1755621862871,"user_tz":-300,"elapsed":27,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"ccc92366-9afd-47c4-90ce-2fb94ca01dd9"},"execution_count":17,"outputs":[{"output_type":"stream","name":"stdout","text":["Is Odd\n","Is Even\n","Is Odd\n","Is Even\n","Is Odd\n","Is Even\n","Is Odd\n","Is Even\n","Is Odd\n"]}]},{"cell_type":"code","source":["for i in range(1 , 11):\n"," if i % 1 == 0:\n"," odd_numbers = i\n","\n"," print(odd_numbers)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"q-kM3BFoN6xN","executionInfo":{"status":"ok","timestamp":1755621980608,"user_tz":-300,"elapsed":8,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"77c184f6-4106-40ef-f404-43706fd4fbc8"},"execution_count":20,"outputs":[{"output_type":"stream","name":"stdout","text":["1\n","2\n","3\n","4\n","5\n","6\n","7\n","8\n","9\n","10\n"]}]},{"cell_type":"code","source":["for i in range(1, 11):\n"," if i % 2 == 0:\n"," even = i\n","\n","print(even)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"xtRykgPXPQ1q","executionInfo":{"status":"ok","timestamp":1755622326128,"user_tz":-300,"elapsed":7,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"3a68806a-4d67-4e27-b27a-6c10e1a34349"},"execution_count":24,"outputs":[{"output_type":"stream","name":"stdout","text":["10\n"]}]},{"cell_type":"code","source":["numbers : list = []\n","\n","for i in range(1, 6):\n"," numbers.append(i)\n","\n","print( numbers)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"9LCxLQVrSgel","executionInfo":{"status":"ok","timestamp":1755623345566,"user_tz":-300,"elapsed":51,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"72d0c47e-4284-47e0-f47d-50efcc8e4493"},"execution_count":43,"outputs":[{"output_type":"stream","name":"stdout","text":["[1, 2, 3, 4, 5]\n"]}]},{"cell_type":"code","source":["for n in numbers:\n"," if n % 2 != 0:\n"," odd_n = n\n"," break\n","\n","print(f'Odd number : {odd_n}')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"fux9ysgaOVBC","executionInfo":{"status":"ok","timestamp":1755623178092,"user_tz":-300,"elapsed":7,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"50f2cd89-eec7-4797-c1ce-afecc46afaaf"},"execution_count":33,"outputs":[{"output_type":"stream","name":"stdout","text":["Odd number : 1\n"]}]},{"cell_type":"code","source":["print('Odd number : {odd_n}')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"xcSf4cO2SEgJ","executionInfo":{"status":"ok","timestamp":1755623155198,"user_tz":-300,"elapsed":7,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"d77c6b91-b7d1-4fa0-d542-6cec75a092e6"},"execution_count":32,"outputs":[{"output_type":"stream","name":"stdout","text":["Odd number : {odd_n}\n"]}]},{"cell_type":"code","source":["numbers"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"R2D7aTB1S2Sp","executionInfo":{"status":"ok","timestamp":1755623404590,"user_tz":-300,"elapsed":9,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"b42f83f0-b80d-4b52-cd57-12332b0b6656"},"execution_count":44,"outputs":[{"output_type":"execute_result","data":{"text/plain":["[1, 2, 3, 4, 5]"]},"metadata":{},"execution_count":44}]},{"cell_type":"code","source":["new_list = []\n","\n","for i in numbers:\n"," new_list.append(i**i)\n","\n","print(new_list)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"1Fg9BcDvTzLH","executionInfo":{"status":"ok","timestamp":1755623569363,"user_tz":-300,"elapsed":37,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"2cb9de78-4394-483b-cc14-badf8163f31d"},"execution_count":52,"outputs":[{"output_type":"stream","name":"stdout","text":["[1, 4, 27, 256, 3125]\n"]}]},{"cell_type":"code","source":["new_list = [(i**2) for i in numbers]\n","new_list"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"WxG_23xAUANd","executionInfo":{"status":"ok","timestamp":1755623633034,"user_tz":-300,"elapsed":7,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"37e5531b-7090-4ab3-b2e8-8b3bf621104c"},"execution_count":57,"outputs":[{"output_type":"execute_result","data":{"text/plain":["[1, 4, 9, 16, 25]"]},"metadata":{},"execution_count":57}]},{"cell_type":"code","source":["def reverse_string(text:str):\n"," return text[::-1]\n","\n","print(reverse_string('Ali'))\n","print(reverse_string('Ammar'))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"tNqBJ11MUlzM","executionInfo":{"status":"ok","timestamp":1755623779004,"user_tz":-300,"elapsed":26,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"ffbfed4f-093b-4c5a-d3ea-f5cefa50c140"},"execution_count":60,"outputs":[{"output_type":"stream","name":"stdout","text":["ilA\n","rammA\n"]}]},{"cell_type":"code","source":["def count_vowels(text:str):\n"," vowels = 'aeiou'\n"," return sum(1 for char in text.lower() if char in vowels)"],"metadata":{"id":"a8cCdAfWVJ5u","executionInfo":{"status":"ok","timestamp":1755623887657,"user_tz":-300,"elapsed":7,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}}},"execution_count":62,"outputs":[]},{"cell_type":"code","source":["count_vowels('Abu Bakr')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"jghO-dV-VkrB","executionInfo":{"status":"ok","timestamp":1755623898906,"user_tz":-300,"elapsed":7,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"befee6c6-e348-45b2-af7d-5c7599405e42"},"execution_count":63,"outputs":[{"output_type":"execute_result","data":{"text/plain":["3"]},"metadata":{},"execution_count":63}]},{"cell_type":"code","source":["count_vowels('Abbas')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"L6fsQyLlVr3K","executionInfo":{"status":"ok","timestamp":1755623966297,"user_tz":-300,"elapsed":12,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"25043a7e-9641-4892-89fd-0abfd3efc685"},"execution_count":72,"outputs":[{"output_type":"execute_result","data":{"text/plain":["2"]},"metadata":{},"execution_count":72}]},{"cell_type":"code","source":["count_vowels('Omer')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"EpNRF9RlVtLD","executionInfo":{"status":"ok","timestamp":1755623974514,"user_tz":-300,"elapsed":54,"user":{"displayName":"Syed Abdullah Bukhari (Imam)","userId":"18410448924632905759"}},"outputId":"00685303-db5e-4867-c215-42603ee7cb10"},"execution_count":73,"outputs":[{"output_type":"execute_result","data":{"text/plain":["2"]},"metadata":{},"execution_count":73}]},{"cell_type":"code","source":[],"metadata":{"id":"PFu_pbyXVwPq"},"execution_count":null,"outputs":[]}]}
Lines changed: 337 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,337 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"provenance": []
7+
},
8+
"kernelspec": {
9+
"name": "python3",
10+
"display_name": "Python 3"
11+
},
12+
"language_info": {
13+
"name": "python"
14+
}
15+
},
16+
"cells": [
17+
{
18+
"cell_type": "code",
19+
"execution_count": 3,
20+
"metadata": {
21+
"id": "Acnj71h-cJ6q",
22+
"colab": {
23+
"base_uri": "https://localhost:8080/"
24+
},
25+
"outputId": "b7e6ef72-4462-44b1-ef84-075b21bad469"
26+
},
27+
"outputs": [
28+
{
29+
"output_type": "stream",
30+
"name": "stdout",
31+
"text": [
32+
"False\n",
33+
"True\n",
34+
"False\n",
35+
"True\n",
36+
"False\n",
37+
"True\n"
38+
]
39+
}
40+
],
41+
"source": [
42+
"numbers: list = [print(n % 2 != 0) for n in range(0,6)]"
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"source": [
48+
"print(numbers)"
49+
],
50+
"metadata": {
51+
"colab": {
52+
"base_uri": "https://localhost:8080/"
53+
},
54+
"id": "j00c1ru7OrIv",
55+
"outputId": "0736482b-1f00-465d-fcc3-75dcb3e66ed9"
56+
},
57+
"execution_count": 2,
58+
"outputs": [
59+
{
60+
"output_type": "stream",
61+
"name": "stdout",
62+
"text": [
63+
"[None, None, None, None, None]\n"
64+
]
65+
}
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"source": [
71+
"# odd_n = []"
72+
],
73+
"metadata": {
74+
"id": "m2AnhkqQPI3V"
75+
},
76+
"execution_count": 15,
77+
"outputs": []
78+
},
79+
{
80+
"cell_type": "code",
81+
"source": [
82+
"# for n in range(1, 6):\n",
83+
"# if n % 2 != 0:\n",
84+
"# odd_n.append(n)\n",
85+
"# else:\n",
86+
"# even_numbers = [n]\n",
87+
"\n",
88+
"# print(odd_n)\n",
89+
"# print(even_numbers)"
90+
],
91+
"metadata": {
92+
"id": "sfljUxooOtrD"
93+
},
94+
"execution_count": 14,
95+
"outputs": []
96+
},
97+
{
98+
"cell_type": "code",
99+
"source": [
100+
"odd_n: list = []\n",
101+
"\n",
102+
"for n in range(1, 6):\n",
103+
" if n % 2 != 0: odd_n.append(n)\n",
104+
"\n",
105+
"print(odd_n)"
106+
],
107+
"metadata": {
108+
"colab": {
109+
"base_uri": "https://localhost:8080/"
110+
},
111+
"id": "rCsrPngROx4Q",
112+
"outputId": "a84a372a-1320-48a1-b6d2-4d90f8fc532b"
113+
},
114+
"execution_count": 18,
115+
"outputs": [
116+
{
117+
"output_type": "stream",
118+
"name": "stdout",
119+
"text": [
120+
"[1, 3, 5]\n"
121+
]
122+
}
123+
]
124+
},
125+
{
126+
"cell_type": "code",
127+
"source": [],
128+
"metadata": {
129+
"id": "EBHH5k93pz4f"
130+
},
131+
"execution_count": null,
132+
"outputs": []
133+
},
134+
{
135+
"cell_type": "code",
136+
"source": [
137+
"for n in range(0 , 1):\n",
138+
" if n % 2 == 0:\n",
139+
" print('Is Even')\n",
140+
" else: print('Is odd')\n",
141+
""
142+
],
143+
"metadata": {
144+
"colab": {
145+
"base_uri": "https://localhost:8080/"
146+
},
147+
"id": "ghpUWAWgPlNN",
148+
"outputId": "d6af0657-d84f-43b5-f468-02ff690f3f85"
149+
},
150+
"execution_count": 19,
151+
"outputs": [
152+
{
153+
"output_type": "stream",
154+
"name": "stdout",
155+
"text": [
156+
"Is Even\n"
157+
]
158+
}
159+
]
160+
},
161+
{
162+
"cell_type": "code",
163+
"source": [
164+
"def check_even_odd() -> int:\n",
165+
" for n in range(0, 1):\n",
166+
" 'Is Even' if n % 2 ==0 else 'Is Odd'"
167+
],
168+
"metadata": {
169+
"id": "4C0NObxxp5I7"
170+
},
171+
"execution_count": 21,
172+
"outputs": []
173+
},
174+
{
175+
"cell_type": "code",
176+
"source": [
177+
"def check_even_odd(x: int , y: int) -> str:\n",
178+
" return 'Is Even' if (x & y % 2 == 0) else 'Is Odd'"
179+
],
180+
"metadata": {
181+
"id": "kC5oH5-lqobx"
182+
},
183+
"execution_count": 23,
184+
"outputs": []
185+
},
186+
{
187+
"cell_type": "code",
188+
"source": [
189+
"print(check_even_odd(12 , 2))\n",
190+
"print(check_even_odd(34 , 21))\n",
191+
"print(check_even_odd(21 , 45))"
192+
],
193+
"metadata": {
194+
"colab": {
195+
"base_uri": "https://localhost:8080/"
196+
},
197+
"id": "75RMtnROq_jh",
198+
"outputId": "df91ba05-eb3f-4e98-ddc5-c9b5255c7be6"
199+
},
200+
"execution_count": 29,
201+
"outputs": [
202+
{
203+
"output_type": "stream",
204+
"name": "stdout",
205+
"text": [
206+
"Is Even\n",
207+
"Is Even\n",
208+
"Is Odd\n"
209+
]
210+
}
211+
]
212+
},
213+
{
214+
"cell_type": "code",
215+
"source": [
216+
"def check_even_n(start: int , end: int) -> None:\n",
217+
" for num in range(start , end + 1):\n",
218+
" if num % 2 == 0:\n",
219+
" print(f' Is Even: {num}')\n",
220+
" else: print(f'Is odd: {num}')\n",
221+
"\n",
222+
"print(check_even_n(3 , 21))"
223+
],
224+
"metadata": {
225+
"colab": {
226+
"base_uri": "https://localhost:8080/"
227+
},
228+
"id": "N8HEjoV3rBsG",
229+
"outputId": "f6e24bc6-885a-49bf-d052-5832343dce68"
230+
},
231+
"execution_count": 33,
232+
"outputs": [
233+
{
234+
"output_type": "stream",
235+
"name": "stdout",
236+
"text": [
237+
"Is odd: 3\n",
238+
" Is Even: 4\n",
239+
"Is odd: 5\n",
240+
" Is Even: 6\n",
241+
"Is odd: 7\n",
242+
" Is Even: 8\n",
243+
"Is odd: 9\n",
244+
" Is Even: 10\n",
245+
"Is odd: 11\n",
246+
" Is Even: 12\n",
247+
"Is odd: 13\n",
248+
" Is Even: 14\n",
249+
"Is odd: 15\n",
250+
" Is Even: 16\n",
251+
"Is odd: 17\n",
252+
" Is Even: 18\n",
253+
"Is odd: 19\n",
254+
" Is Even: 20\n",
255+
"Is odd: 21\n",
256+
"None\n"
257+
]
258+
}
259+
]
260+
},
261+
{
262+
"cell_type": "code",
263+
"source": [
264+
"def check_even_n(start: int , end: int) -> None:\n",
265+
" return [f'is Even {num}' if num % 2 == 0 else f'Is Odd: {num}' for num in range(start , end + 1)]\n",
266+
"\n",
267+
"print(check_even_n(1 , 21))"
268+
],
269+
"metadata": {
270+
"colab": {
271+
"base_uri": "https://localhost:8080/"
272+
},
273+
"id": "tI7XdjoGrwXC",
274+
"outputId": "06f42567-5db4-4425-9ad2-e0ec5ab2e87e"
275+
},
276+
"execution_count": 40,
277+
"outputs": [
278+
{
279+
"output_type": "stream",
280+
"name": "stdout",
281+
"text": [
282+
"['Is Odd: 1', 'is Even 2', 'Is Odd: 3', 'is Even 4', 'Is Odd: 5', 'is Even 6', 'Is Odd: 7', 'is Even 8', 'Is Odd: 9', 'is Even 10', 'Is Odd: 11', 'is Even 12', 'Is Odd: 13', 'is Even 14', 'Is Odd: 15', 'is Even 16', 'Is Odd: 17', 'is Even 18', 'Is Odd: 19', 'is Even 20', 'Is Odd: 21']\n"
283+
]
284+
}
285+
]
286+
},
287+
{
288+
"cell_type": "code",
289+
"source": [
290+
"result = check_even_n(3, 17)\n",
291+
"\n",
292+
"for i in result:\n",
293+
" print(i)"
294+
],
295+
"metadata": {
296+
"colab": {
297+
"base_uri": "https://localhost:8080/"
298+
},
299+
"id": "dv9RXbFcsKMt",
300+
"outputId": "3ca9b051-0f41-40f6-9d61-2846da1f82a9"
301+
},
302+
"execution_count": 42,
303+
"outputs": [
304+
{
305+
"output_type": "stream",
306+
"name": "stdout",
307+
"text": [
308+
"Is Odd: 3\n",
309+
"is Even 4\n",
310+
"Is Odd: 5\n",
311+
"is Even 6\n",
312+
"Is Odd: 7\n",
313+
"is Even 8\n",
314+
"Is Odd: 9\n",
315+
"is Even 10\n",
316+
"Is Odd: 11\n",
317+
"is Even 12\n",
318+
"Is Odd: 13\n",
319+
"is Even 14\n",
320+
"Is Odd: 15\n",
321+
"is Even 16\n",
322+
"Is Odd: 17\n"
323+
]
324+
}
325+
]
326+
},
327+
{
328+
"cell_type": "code",
329+
"source": [],
330+
"metadata": {
331+
"id": "rEXmyQ4otUzj"
332+
},
333+
"execution_count": null,
334+
"outputs": []
335+
}
336+
]
337+
}

0 commit comments

Comments
 (0)