Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a53d900

Browse files
committed
condition01_CompareValues
1 parent f5733ce commit a53d900

File tree

2 files changed

+522
-0
lines changed

2 files changed

+522
-0
lines changed
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "7486da82",
6+
"metadata": {},
7+
"source": [
8+
"### Compare Values\n",
9+
"#### Solutions to review exercises"
10+
]
11+
},
12+
{
13+
"cell_type": "markdown",
14+
"id": "74427ff0",
15+
"metadata": {},
16+
"source": [
17+
"- **Exercise 1**\n",
18+
"- Test whether these expressions are True or False"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 1,
24+
"id": "5233803b",
25+
"metadata": {},
26+
"outputs": [
27+
{
28+
"name": "stdout",
29+
"output_type": "stream",
30+
"text": [
31+
"True\n",
32+
"False\n",
33+
"True\n",
34+
"True\n",
35+
"True\n",
36+
"False\n"
37+
]
38+
}
39+
],
40+
"source": [
41+
"print(1 <= 1)\n",
42+
"print(1 != 1)\n",
43+
"print(1 != 2)\n",
44+
"print(\"good\" != \"bad\")\n",
45+
"print(\"good\" != \"Good\")\n",
46+
"print(123 == \"123\")"
47+
]
48+
},
49+
{
50+
"cell_type": "markdown",
51+
"id": "b85022fd",
52+
"metadata": {},
53+
"source": [
54+
"- **Exercise 2**\n",
55+
"- Fill in the blank so that each of the following expressions are True\n"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": 2,
61+
"id": "af1bbd94",
62+
"metadata": {},
63+
"outputs": [
64+
{
65+
"name": "stdout",
66+
"output_type": "stream",
67+
"text": [
68+
"iii) True\n"
69+
]
70+
}
71+
],
72+
"source": [
73+
"# 3 __ 4\n",
74+
"# Any of the following:\n",
75+
"#i) 3 < 4\n",
76+
"#ii) 3 <= 4\n",
77+
"#iii) 3 != 4\n",
78+
"print(\"iii) \",3 != 4)\n"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": 3,
84+
"id": "7196aa8b",
85+
"metadata": {},
86+
"outputs": [
87+
{
88+
"name": "stdout",
89+
"output_type": "stream",
90+
"text": [
91+
"iii) True\n"
92+
]
93+
}
94+
],
95+
"source": [
96+
"# 10 __ 5\n",
97+
"# Any of the following:\n",
98+
"#i) 10 > 5\n",
99+
"#ii) 10 >= 5\n",
100+
"#iii) 10 != 5\n",
101+
"print(\"iii) \",10 != 5)\n"
102+
]
103+
},
104+
{
105+
"cell_type": "code",
106+
"execution_count": 4,
107+
"id": "d9bdddb7",
108+
"metadata": {},
109+
"outputs": [
110+
{
111+
"name": "stdout",
112+
"output_type": "stream",
113+
"text": [
114+
"iii) True\n"
115+
]
116+
}
117+
],
118+
"source": [
119+
"# \"jack\" __ \"jill\"\n",
120+
"# Any of the following:\n",
121+
"#i) \"jack\" < \"jill\"\n",
122+
"#ii) \"jack\" <= \"jill\"\n",
123+
"#iii) \"jack\" != \"jill\"\n",
124+
"print(\"iii) \",\"jack\" != \"jill\")\n"
125+
]
126+
},
127+
{
128+
"cell_type": "code",
129+
"execution_count": 5,
130+
"id": "45005467",
131+
"metadata": {},
132+
"outputs": [
133+
{
134+
"name": "stdout",
135+
"output_type": "stream",
136+
"text": [
137+
"use not equal operator : True\n"
138+
]
139+
}
140+
],
141+
"source": [
142+
"# 42 __ \"42\"\n",
143+
"print(\"use not equal operator : \",42 != \"42\")"
144+
]
145+
},
146+
{
147+
"cell_type": "markdown",
148+
"id": "ef5de069",
149+
"metadata": {},
150+
"source": [
151+
"- **Exercise 3**\n",
152+
"- Write a Python program to count the number of even and odd numbers from given range from user"
153+
]
154+
},
155+
{
156+
"cell_type": "code",
157+
"execution_count": 6,
158+
"id": "83d145b6",
159+
"metadata": {},
160+
"outputs": [
161+
{
162+
"name": "stdout",
163+
"output_type": "stream",
164+
"text": [
165+
"10\n",
166+
"Number of even numbers : 5\n",
167+
"Number of odd numbers : 5\n"
168+
]
169+
}
170+
],
171+
"source": [
172+
"number = []\n",
173+
"count_odd = 0\n",
174+
"count_even = 0\n",
175+
"times = int(input())\n",
176+
"for i in range(times):\n",
177+
" number.append(i)\n",
178+
"\n",
179+
" \n",
180+
"for x in number:\n",
181+
" if not x % 2:\n",
182+
" count_even+=1\n",
183+
" else:\n",
184+
" count_odd+=1 \n",
185+
" \n",
186+
"\n",
187+
"print(\"Number of even numbers :\",count_even)\n",
188+
"print(\"Number of odd numbers :\",count_odd)"
189+
]
190+
},
191+
{
192+
"cell_type": "markdown",
193+
"id": "03cf484e",
194+
"metadata": {},
195+
"source": [
196+
"- **Exercise 4**\n",
197+
"- When Object Copy Is Equal but Not Identical\n"
198+
]
199+
},
200+
{
201+
"cell_type": "code",
202+
"execution_count": 7,
203+
"id": "b0f40621",
204+
"metadata": {},
205+
"outputs": [
206+
{
207+
"name": "stdout",
208+
"output_type": "stream",
209+
"text": [
210+
"['Pritom', 'Saha', 'Hello World']\n",
211+
"['Pritom', 'Saha', 'Hello World']\n",
212+
"Equal : True\n",
213+
"Is opreator : False\n",
214+
"ID of a : 2879757711296\n",
215+
"ID of b : 2879757709376\n"
216+
]
217+
}
218+
],
219+
"source": [
220+
"\n",
221+
"a = [\"Pritom\", \"Saha\", \"Hello World\"]\n",
222+
"b = a.copy()\n",
223+
"print(a)\n",
224+
"print(b)\n",
225+
"print(\"Equal : \",a == b)\n",
226+
"print(\"Is opreator : \",a is b)\n",
227+
"print(\"ID of a : \",id(a))\n",
228+
"print(\"ID of b : \",id(b))"
229+
]
230+
},
231+
{
232+
"cell_type": "code",
233+
"execution_count": null,
234+
"id": "3a640df2",
235+
"metadata": {},
236+
"outputs": [],
237+
"source": []
238+
}
239+
],
240+
"metadata": {
241+
"kernelspec": {
242+
"display_name": "Python 3 (ipykernel)",
243+
"language": "python",
244+
"name": "python3"
245+
},
246+
"language_info": {
247+
"codemirror_mode": {
248+
"name": "ipython",
249+
"version": 3
250+
},
251+
"file_extension": ".py",
252+
"mimetype": "text/x-python",
253+
"name": "python",
254+
"nbconvert_exporter": "python",
255+
"pygments_lexer": "ipython3",
256+
"version": "3.9.13"
257+
}
258+
},
259+
"nbformat": 4,
260+
"nbformat_minor": 5
261+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /