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 854440a

Browse files
Add files via upload
1 parent 0c0ddb2 commit 854440a

File tree

1 file changed

+366
-0
lines changed

1 file changed

+366
-0
lines changed

‎Day18(16may19).ipynb‎

Lines changed: 366 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,366 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": []
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"## Problem 1:\n",
15+
"\n",
16+
"### Statement\n",
17+
"Define a function to read data from text file\\\n"
18+
]
19+
},
20+
{
21+
"cell_type": "code",
22+
"execution_count": 16,
23+
"metadata": {},
24+
"outputs": [
25+
{
26+
"data": {
27+
"text/plain": [
28+
"'Hello!\\nMr\\n'"
29+
]
30+
},
31+
"execution_count": 16,
32+
"metadata": {},
33+
"output_type": "execute_result"
34+
}
35+
],
36+
"source": [
37+
"def ReadFileData(filename):\n",
38+
" f=open(filename,'r')\n",
39+
" filedata=f.readline()\n",
40+
" filedata+=f.readline()\n",
41+
" \n",
42+
" f.close()\n",
43+
" return filedata\n",
44+
"\n",
45+
"ReadFileData('DataFiles/data.txt')"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": 17,
51+
"metadata": {},
52+
"outputs": [
53+
{
54+
"data": {
55+
"text/plain": [
56+
"'Hello!\\nMr\\nThis\\nis\\nPython'"
57+
]
58+
},
59+
"execution_count": 17,
60+
"metadata": {},
61+
"output_type": "execute_result"
62+
}
63+
],
64+
"source": [
65+
"def readfiledata(filename):\n",
66+
" f = open(filename, 'r')\n",
67+
" filedata = f.read()\n",
68+
" \n",
69+
" f.close()\n",
70+
" return filedata\n",
71+
"\n",
72+
"readfiledata('DataFiles/data.txt')"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": 18,
78+
"metadata": {},
79+
"outputs": [
80+
{
81+
"data": {
82+
"text/plain": [
83+
"'Hello!\\n'"
84+
]
85+
},
86+
"execution_count": 18,
87+
"metadata": {},
88+
"output_type": "execute_result"
89+
}
90+
],
91+
"source": [
92+
"def readfiledata(filename):\n",
93+
" with open(filename, 'r') as f:\n",
94+
" filedata = f.readline()\n",
95+
" \n",
96+
"\n",
97+
" return filedata\n",
98+
"\n",
99+
"readfiledata('DataFiles/data.txt')"
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": 337,
105+
"metadata": {},
106+
"outputs": [
107+
{
108+
"name": "stdout",
109+
"output_type": "stream",
110+
"text": [
111+
"Hello!\n",
112+
"\n",
113+
"Mr\n",
114+
"\n",
115+
"This\n",
116+
"\n",
117+
"is\n",
118+
"\n",
119+
"Python\n"
120+
]
121+
}
122+
],
123+
"source": [
124+
"def readfiledata(filename):\n",
125+
" with open(filename, 'r') as f:\n",
126+
" for line in f:\n",
127+
" print(line)\n",
128+
"\n",
129+
"readfiledata('DataFiles/data.txt')"
130+
]
131+
},
132+
{
133+
"cell_type": "code",
134+
"execution_count": 338,
135+
"metadata": {},
136+
"outputs": [
137+
{
138+
"name": "stdout",
139+
"output_type": "stream",
140+
"text": [
141+
"Hello!\n",
142+
"Mr\n",
143+
"This\n",
144+
"is\n",
145+
"Python"
146+
]
147+
}
148+
],
149+
"source": [
150+
"def readfiledata(filename):\n",
151+
" with open(filename, 'r') as f:\n",
152+
" for line in f:\n",
153+
" print(line, end = '')\n",
154+
"\n",
155+
"readfiledata('DataFiles/data.txt')"
156+
]
157+
},
158+
{
159+
"cell_type": "code",
160+
"execution_count": 340,
161+
"metadata": {},
162+
"outputs": [
163+
{
164+
"name": "stdout",
165+
"output_type": "stream",
166+
"text": [
167+
"Hello!\n",
168+
"Mr\n",
169+
"This\n",
170+
"is\n",
171+
"Python\n"
172+
]
173+
}
174+
],
175+
"source": [
176+
"def readfiledata(filename):\n",
177+
" with open(filename, 'r') as f:\n",
178+
" print(f.read())\n",
179+
"\n",
180+
"readfiledata('DataFiles/data.txt')"
181+
]
182+
},
183+
{
184+
"cell_type": "code",
185+
"execution_count": null,
186+
"metadata": {},
187+
"outputs": [],
188+
"source": []
189+
},
190+
{
191+
"cell_type": "markdown",
192+
"metadata": {},
193+
"source": [
194+
"## Problem 2:\n",
195+
"Define a function to generate a Marks data file (text file) for 1300 students such that each mark is entered in anew line. Marks range from 0 to 100 (inclusive) random numbers."
196+
]
197+
},
198+
{
199+
"cell_type": "code",
200+
"execution_count": 347,
201+
"metadata": {},
202+
"outputs": [
203+
{
204+
"data": {
205+
"text/plain": [
206+
"0.009846191001997795"
207+
]
208+
},
209+
"execution_count": 347,
210+
"metadata": {},
211+
"output_type": "execute_result"
212+
}
213+
],
214+
"source": [
215+
"import random,timeit\n",
216+
"def GenerateMarksData(n,filename):\n",
217+
" start=timeit.default_timer()\n",
218+
" with open(filename,'w') as marksFile:\n",
219+
" for i in range(n):\n",
220+
" marks=random.randint(1,100)\n",
221+
" marksFile.write(str(marks)+'\\n')\n",
222+
" return timeit.default_timer()-start\n",
223+
"\n",
224+
"GenerateMarksData(1300,'MarksData.txt')"
225+
]
226+
},
227+
{
228+
"cell_type": "code",
229+
"execution_count": null,
230+
"metadata": {},
231+
"outputs": [],
232+
"source": []
233+
},
234+
{
235+
"cell_type": "markdown",
236+
"metadata": {},
237+
"source": [
238+
"## Problem 3:\n",
239+
"Generate a report on marks data with the following indicators:\n",
240+
"* Highest mark :\n",
241+
"* Lowest Mark :\n",
242+
"* Average Mark :\n",
243+
"* No of students with distinction(>90) :\n",
244+
"* No of students with First class (>80):\n",
245+
"* No of students with second class (>70):\n",
246+
"* No of students with second class (>60):\n",
247+
"* No of students failed (<40) :\n",
248+
"### Test Cases\n"
249+
]
250+
},
251+
{
252+
"cell_type": "code",
253+
"execution_count": 349,
254+
"metadata": {},
255+
"outputs": [
256+
{
257+
"name": "stdout",
258+
"output_type": "stream",
259+
"text": [
260+
"Max Marks= 57 Min Marks= 57 Avg Marks= 0\n",
261+
"Grade A-- 0 Grade B-- 0 Grade C-- 0 Grade F-- 0 "
262+
]
263+
},
264+
{
265+
"data": {
266+
"text/plain": [
267+
"0.004933976000756957"
268+
]
269+
},
270+
"execution_count": 349,
271+
"metadata": {},
272+
"output_type": "execute_result"
273+
}
274+
],
275+
"source": [
276+
"import timeit\n",
277+
"def ReadMarks(n,filename):\n",
278+
" start=timeit.default_timer()\n",
279+
" with open (filename,'r') as rip:\n",
280+
" l=[]\n",
281+
" ga=[]\n",
282+
" gc=[]\n",
283+
" gb=[]\n",
284+
" fl=[]\n",
285+
" for i in rip:\n",
286+
" l.append(int(i))\n",
287+
" print('Max Marks=',max(l),'Min Marks=',min(l),'Avg Marks=',(sum(l)//n),end='\\n')\n",
288+
" if int(i)>=90:\n",
289+
" ga.append(int(i))\n",
290+
" elif int(i)>=80 and int(i)<90:\n",
291+
" gb.append(int(i))\n",
292+
" elif int(i)>=70 and int(i)<80:\n",
293+
" gc.append(int(i))\n",
294+
" elif int(i)<=40:\n",
295+
" fl.append(int(i))\n",
296+
" print('Grade A--',len(ga),'Grade B--',len(gb),'Grade C--',len(gc),'Grade F--',len(fl), end = ' ')\n",
297+
" return timeit.default_timer()-start\n",
298+
"\n",
299+
"ReadMarks(1300,'MarksData.txt')\n"
300+
]
301+
},
302+
{
303+
"cell_type": "code",
304+
"execution_count": null,
305+
"metadata": {},
306+
"outputs": [],
307+
"source": []
308+
},
309+
{
310+
"cell_type": "code",
311+
"execution_count": 350,
312+
"metadata": {},
313+
"outputs": [
314+
{
315+
"name": "stdout",
316+
"output_type": "stream",
317+
"text": [
318+
"['4', '36.543', '2', '8', '8']\n",
319+
"[4.0, 36.543, 2.0, 8.0, 8.0]\n",
320+
"[4.0, 36.543, 2.0, 8.0, 8.0]\n",
321+
"0.00058624000303098\n",
322+
"<class 'list'>\n"
323+
]
324+
}
325+
],
326+
"source": [
327+
"import timeit\n",
328+
"st=timeit.default_timer()\n",
329+
"li=[4,36.543,2,8,8]\n",
330+
"print(list(map(str,li)))\n",
331+
"print([float(i) for i in li])\n",
332+
"print(s)\n",
333+
"print((timeit.default_timer()-st))\n",
334+
"print(type(s))"
335+
]
336+
},
337+
{
338+
"cell_type": "code",
339+
"execution_count": null,
340+
"metadata": {},
341+
"outputs": [],
342+
"source": []
343+
}
344+
],
345+
"metadata": {
346+
"kernelspec": {
347+
"display_name": "Python 3",
348+
"language": "python",
349+
"name": "python3"
350+
},
351+
"language_info": {
352+
"codemirror_mode": {
353+
"name": "ipython",
354+
"version": 3
355+
},
356+
"file_extension": ".py",
357+
"mimetype": "text/x-python",
358+
"name": "python",
359+
"nbconvert_exporter": "python",
360+
"pygments_lexer": "ipython3",
361+
"version": "3.7.3"
362+
}
363+
},
364+
"nbformat": 4,
365+
"nbformat_minor": 2
366+
}

0 commit comments

Comments
(0)

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