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