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 acb7dc1

Browse files
function that returns True if a given inequality expression is correct and False (3<7<11)
1 parent 8196cc9 commit acb7dc1

File tree

1 file changed

+244
-0
lines changed

1 file changed

+244
-0
lines changed

‎Assignment-17.ipynb

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "0b0eb982",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"def even_sum(a,b,c):\n",
11+
" add=0\n",
12+
" for i in range(a,b+1):\n",
13+
" if i%c==0:\n",
14+
" add+=i\n",
15+
" else:\n",
16+
" if add == 0:\n",
17+
" print(\"No number between {} and {} can be evenly divided by {}\".format(a,b,c))\n",
18+
" print(add)"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 30,
24+
"id": "3ef90f25",
25+
"metadata": {},
26+
"outputs": [
27+
{
28+
"name": "stdout",
29+
"output_type": "stream",
30+
"text": [
31+
"No number between 1 and 10 can be evenly divided by 20\n",
32+
"0\n"
33+
]
34+
}
35+
],
36+
"source": [
37+
"even_sum(1,10,20)"
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"execution_count": 28,
43+
"id": "aefd412f",
44+
"metadata": {},
45+
"outputs": [
46+
{
47+
"name": "stdout",
48+
"output_type": "stream",
49+
"text": [
50+
"30\n"
51+
]
52+
}
53+
],
54+
"source": [
55+
"even_sum(1,10,2)"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": 29,
61+
"id": "0c164e55",
62+
"metadata": {},
63+
"outputs": [
64+
{
65+
"name": "stdout",
66+
"output_type": "stream",
67+
"text": [
68+
"18\n"
69+
]
70+
}
71+
],
72+
"source": [
73+
"even_sum(1,10,3)"
74+
]
75+
},
76+
{
77+
"cell_type": "code",
78+
"execution_count": 3,
79+
"id": "216180e4",
80+
"metadata": {},
81+
"outputs": [],
82+
"source": [
83+
"def correct_signs(deg): \n",
84+
" if all(i.isnumeric() or i in \"< >.\" for i in deg):\n",
85+
" return eval(deg)"
86+
]
87+
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": 4,
91+
"id": "c02a21b9",
92+
"metadata": {},
93+
"outputs": [
94+
{
95+
"name": "stdout",
96+
"output_type": "stream",
97+
"text": [
98+
"True\n",
99+
"False\n",
100+
"True\n"
101+
]
102+
}
103+
],
104+
"source": [
105+
"print(correct_signs(\"3 < 7 < 11\"))\n",
106+
"print(correct_signs(\"13 > 44 > 33 > 1\"))\n",
107+
"print(correct_signs(\"1 < 2 < 6 < 9 > 3\"))"
108+
]
109+
},
110+
{
111+
"cell_type": "code",
112+
"execution_count": 16,
113+
"id": "51c4cd0d",
114+
"metadata": {},
115+
"outputs": [],
116+
"source": [
117+
"def replace_vowels(svalue,schr):\n",
118+
" vow=\"aeiou\"\n",
119+
" for i in vow:\n",
120+
" svalue=svalue.replace(i,schr)\n",
121+
" return svalue "
122+
]
123+
},
124+
{
125+
"cell_type": "code",
126+
"execution_count": 21,
127+
"id": "121baaa8",
128+
"metadata": {},
129+
"outputs": [
130+
{
131+
"data": {
132+
"text/plain": [
133+
"'th# ##rdv#rk'"
134+
]
135+
},
136+
"execution_count": 21,
137+
"metadata": {},
138+
"output_type": "execute_result"
139+
}
140+
],
141+
"source": [
142+
"replace_vowels(\"the aardvark\",\"#\")"
143+
]
144+
},
145+
{
146+
"cell_type": "code",
147+
"execution_count": 19,
148+
"id": "5fe3d35b",
149+
"metadata": {},
150+
"outputs": [
151+
{
152+
"data": {
153+
"text/plain": [
154+
"'m?nn?? m??s?'"
155+
]
156+
},
157+
"execution_count": 19,
158+
"metadata": {},
159+
"output_type": "execute_result"
160+
}
161+
],
162+
"source": [
163+
"replace_vowels(\"minnie mouse\", \"?\")"
164+
]
165+
},
166+
{
167+
"cell_type": "code",
168+
"execution_count": 20,
169+
"id": "d09bf169",
170+
"metadata": {},
171+
"outputs": [
172+
{
173+
"data": {
174+
"text/plain": [
175+
"'sh*k*sp**r*'"
176+
]
177+
},
178+
"execution_count": 20,
179+
"metadata": {},
180+
"output_type": "execute_result"
181+
}
182+
],
183+
"source": [
184+
"replace_vowels(\"shakespeare\", \"*\")"
185+
]
186+
},
187+
{
188+
"cell_type": "code",
189+
"execution_count": 24,
190+
"id": "6908ddc0",
191+
"metadata": {},
192+
"outputs": [],
193+
"source": [
194+
"def factorial(n):\n",
195+
" if n ==0:\n",
196+
" return 1\n",
197+
" else:\n",
198+
" return n*factorial(n-1)"
199+
]
200+
},
201+
{
202+
"cell_type": "code",
203+
"execution_count": 25,
204+
"id": "41e8ed65",
205+
"metadata": {},
206+
"outputs": [
207+
{
208+
"data": {
209+
"text/plain": [
210+
"120"
211+
]
212+
},
213+
"execution_count": 25,
214+
"metadata": {},
215+
"output_type": "execute_result"
216+
}
217+
],
218+
"source": [
219+
"factorial(5)"
220+
]
221+
}
222+
],
223+
"metadata": {
224+
"kernelspec": {
225+
"display_name": "Python 3",
226+
"language": "python",
227+
"name": "python3"
228+
},
229+
"language_info": {
230+
"codemirror_mode": {
231+
"name": "ipython",
232+
"version": 3
233+
},
234+
"file_extension": ".py",
235+
"mimetype": "text/x-python",
236+
"name": "python",
237+
"nbconvert_exporter": "python",
238+
"pygments_lexer": "ipython3",
239+
"version": "3.6.9"
240+
}
241+
},
242+
"nbformat": 4,
243+
"nbformat_minor": 5
244+
}

0 commit comments

Comments
(0)

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