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 04ad279

Browse files
Add files via upload
1 parent b69daa5 commit 04ad279

File tree

1 file changed

+288
-0
lines changed

1 file changed

+288
-0
lines changed

‎Assignment-10.ipynb

Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "e1db1fa7",
7+
"metadata": {},
8+
"outputs": [
9+
{
10+
"name": "stdout",
11+
"output_type": "stream",
12+
"text": [
13+
"How many numbers you want to insert: 4\n",
14+
"Enter number you want to insert 2\n",
15+
"Enter number you want to insert 4\n",
16+
"Enter number you want to insert 7\n",
17+
"Enter number you want to insert 8\n",
18+
"Sum of elements in given list is : 21\n"
19+
]
20+
}
21+
],
22+
"source": [
23+
"lst = []\n",
24+
"num = int(input('How many numbers you want to insert: '))\n",
25+
"for n in range(num):\n",
26+
" numbers = int(input('Enter number you want to insert '))\n",
27+
" lst.append(numbers)\n",
28+
"print(\"Sum of elements in given list is :\", sum(lst))"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": 42,
34+
"id": "ff02560b",
35+
"metadata": {},
36+
"outputs": [
37+
{
38+
"name": "stdout",
39+
"output_type": "stream",
40+
"text": [
41+
"Multiplication of the given elements in the list is 120\n"
42+
]
43+
}
44+
],
45+
"source": [
46+
"lst=[1,2,3,4,5]\n",
47+
"mul=1\n",
48+
"for i in lst:\n",
49+
" mul=mul*i\n",
50+
"print('Multiplication of the given elements in the list is',mul)"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": 14,
56+
"id": "550648bd",
57+
"metadata": {},
58+
"outputs": [
59+
{
60+
"name": "stdout",
61+
"output_type": "stream",
62+
"text": [
63+
"Smallest Number from the given list is 2\n"
64+
]
65+
}
66+
],
67+
"source": [
68+
"lst=[23,54,6,8,4,2,19]\n",
69+
"print('Smallest Number from the given list is',min(lst))"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": 15,
75+
"id": "f3f7a109",
76+
"metadata": {},
77+
"outputs": [
78+
{
79+
"name": "stdout",
80+
"output_type": "stream",
81+
"text": [
82+
"Maximum Number from the given list is 54\n"
83+
]
84+
}
85+
],
86+
"source": [
87+
"lst=[23,54,6,8,4,2,19]\n",
88+
"print('Maximum Number from the given list is',max(lst))"
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": 29,
94+
"id": "56ec5351",
95+
"metadata": {},
96+
"outputs": [
97+
{
98+
"name": "stdout",
99+
"output_type": "stream",
100+
"text": [
101+
"Sorted List: [2, 4, 6, 8, 19, 23, 54]\n",
102+
"The Second Largest element in the list is 23\n"
103+
]
104+
}
105+
],
106+
"source": [
107+
"lst=[23,54,6,8,4,2,19]\n",
108+
"lst.sort()\n",
109+
"print(\"Sorted List:\",lst)\n",
110+
"print(\"The Second Largest element in the list is\",lst[-2])"
111+
]
112+
},
113+
{
114+
"cell_type": "code",
115+
"execution_count": 44,
116+
"id": "08c6bca3",
117+
"metadata": {},
118+
"outputs": [
119+
{
120+
"name": "stdout",
121+
"output_type": "stream",
122+
"text": [
123+
"Enter number: 2\n",
124+
"Sorted List: [2, 4, 6, 8, 19, 23, 54]\n",
125+
"The 2 Largest elements in the list are [23, 54]\n"
126+
]
127+
}
128+
],
129+
"source": [
130+
"lst=[23,54,6,8,4,2,19]\n",
131+
"num=int(input(\"Enter number: \"))\n",
132+
"if(num > len(lst)):\n",
133+
" print(\"Sorry You have entered Number greater than the size of list\")\n",
134+
"else:\n",
135+
" lst.sort()\n",
136+
" print(\"Sorted List:\",lst)\n",
137+
" print(\"The\" ,num, \"Largest elements in the list are\",lst[-num:])"
138+
]
139+
},
140+
{
141+
"cell_type": "code",
142+
"execution_count": 33,
143+
"id": "b128e2cf",
144+
"metadata": {},
145+
"outputs": [
146+
{
147+
"data": {
148+
"text/plain": [
149+
"[0, 2, 4, 6, 8, 10]"
150+
]
151+
},
152+
"execution_count": 33,
153+
"metadata": {},
154+
"output_type": "execute_result"
155+
}
156+
],
157+
"source": [
158+
"[even for even in range(11) if even%2==0]"
159+
]
160+
},
161+
{
162+
"cell_type": "code",
163+
"execution_count": 34,
164+
"id": "6a8533a6",
165+
"metadata": {},
166+
"outputs": [
167+
{
168+
"data": {
169+
"text/plain": [
170+
"[1, 3, 5, 7, 9]"
171+
]
172+
},
173+
"execution_count": 34,
174+
"metadata": {},
175+
"output_type": "execute_result"
176+
}
177+
],
178+
"source": [
179+
"[odd for odd in range(11) if odd%2!=0]"
180+
]
181+
},
182+
{
183+
"cell_type": "code",
184+
"execution_count": 38,
185+
"id": "389db9d7",
186+
"metadata": {},
187+
"outputs": [
188+
{
189+
"name": "stdout",
190+
"output_type": "stream",
191+
"text": [
192+
"After Removing Empty lists inside list: ['Akash', 'Borgalli', 23, 4, 5, 6, 7, 8, [23, 89, 76], True, False, 12.5, 89.87]\n"
193+
]
194+
}
195+
],
196+
"source": [
197+
"lst=['Akash','Borgalli',23,4,5,6,7,8,[23,89,76],[],True,[],False,12.5,89.87]\n",
198+
"for i in lst:\n",
199+
" if type(i)== list and len(i)==0:\n",
200+
" lst.remove(i)\n",
201+
"print('After Removing Empty lists inside list:',lst) "
202+
]
203+
},
204+
{
205+
"cell_type": "code",
206+
"execution_count": 41,
207+
"id": "a15c6b20",
208+
"metadata": {},
209+
"outputs": [
210+
{
211+
"name": "stdout",
212+
"output_type": "stream",
213+
"text": [
214+
"[1, 2, 3, 4]\n",
215+
"[1, 2, 3, 4]\n",
216+
"After Update List1 remains same because of copy function: [1, 2, 3, 4]\n",
217+
"Updated list 2 [1, 1998, 3, 4]\n"
218+
]
219+
}
220+
],
221+
"source": [
222+
"## shallow copy\n",
223+
"lst1=[1,2,3,4]\n",
224+
"lst2=lst1.copy()\n",
225+
"print(lst1)\n",
226+
"print(lst2)\n",
227+
"lst2[1]=1998\n",
228+
"print('After Update List1 remains same because of copy function:',lst1)\n",
229+
"print('Updated list 2',lst2)"
230+
]
231+
},
232+
{
233+
"cell_type": "code",
234+
"execution_count": 57,
235+
"id": "bf6281f1",
236+
"metadata": {},
237+
"outputs": [
238+
{
239+
"name": "stdout",
240+
"output_type": "stream",
241+
"text": [
242+
"Akash occured 2 times\n",
243+
"5 occured 3 times\n",
244+
"Borgalli occured 1 times\n",
245+
"23 occured 1 times\n",
246+
"4 occured 4 times\n",
247+
"45 occured 2 times\n",
248+
"6 occured 1 times\n",
249+
"7 occured 2 times\n",
250+
"3 occured 1 times\n",
251+
"8 occured 1 times\n"
252+
]
253+
}
254+
],
255+
"source": [
256+
"lst=['Akash',5,'Borgalli',23,4,'Akash',45,6,7,7,45,4,3,8,5,4,5,4]\n",
257+
"st= set()\n",
258+
"for i in lst:\n",
259+
" if i in st:\n",
260+
" pass\n",
261+
" else:\n",
262+
" print(i,'occured',lst.count(i),'times')\n",
263+
" st.add(i) "
264+
]
265+
}
266+
],
267+
"metadata": {
268+
"kernelspec": {
269+
"display_name": "Python 3",
270+
"language": "python",
271+
"name": "python3"
272+
},
273+
"language_info": {
274+
"codemirror_mode": {
275+
"name": "ipython",
276+
"version": 3
277+
},
278+
"file_extension": ".py",
279+
"mimetype": "text/x-python",
280+
"name": "python",
281+
"nbconvert_exporter": "python",
282+
"pygments_lexer": "ipython3",
283+
"version": "3.6.9"
284+
}
285+
},
286+
"nbformat": 4,
287+
"nbformat_minor": 5
288+
}

0 commit comments

Comments
(0)

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