-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathassignment14_file.py
More file actions
66 lines (52 loc) · 1.13 KB
/
assignment14_file.py
File metadata and controls
66 lines (52 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
print("question no 01")
c=0
count_line=0
n=int(input("enter the no of lines which you wannt to print from last:"))
f=open("test.txt",'r')
for line in f:
count_line=count_line+1
m=count_line-n
f.seek(0)
for line in f:
c+=1
if c>m:
print(line)
print("question no 02")
with open('test.txt','r') as f:
content=f.read()
words=content.split()
print(words)
s=set(words)
print(s)
for n in s:
print(n,words.count(n))
print("question no 03")
with open('test.txt','r') as f1:
with open('test1.txt','w') as f2:
for line in f1:
f2.write(line)
print("question no 04")
with open('test.txt','r') as f1:
c1=f1.readlines()
with open('test1.txt','r') as f1:
c2=f1.readlines()
i=0
for a in c1:
print(c1[i]+c2[i])
i=i+1
print('question no 05')
import random
with open ('test.txt','w')as f1:
for i in range(10):
m=random.randint(0,9)
f1.write(str(m))
f1.write("\n")
with open("test.txt",'r')as f:
l=f.readlines()
print(l)
l.sort()
print(l)
with open ('test1.txt','w')as f1:
for n in l:
f1.write(n)
f1.write('\n')