-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkalyani.txt
171 lines (147 loc) · 3.26 KB
/
kalyani.txt
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
HII....I am Kalyani Chaudhari..
I am studying in TY BCS Computer Science at RBNB College.
I am from Jalgaon.
I am learning Java,PHp,python,DS,OS etc..
#Write a python program to write a list to a file.
f1=open("abc.txt","w")
l1=["java","php","python"]
for i in l1:
f1.write(i+"\n")
f1.close()
print("Write Successfully...")
#Write a python program to get the file size of a plain file
f=open("abc.txt","r")
s=f.read()
print("size =",len(s))
f.close()
#Write a python program to count the frequency of words in a file
f1=open("abc.txt","r")
s=f1.read()
s1=s.split(" ")
l1=[]
for i in s1:
if i not in l1:
print(i,"count",s1.count(i))
l1.append(i)
f1.close()
#Write a python program to count the frequency of words in a file
f1=open("abc.txt","r")
c=0
while True:
s=f1.readline()
c=c+1;
if s=="":
break;
print("number of lines =",c)
f1.close()
#Write a python program to find the longest words
f1=open("abc.txt","r")
s=f1.read()
s1=s.split(" ")
s2=""
for i in s1:
if len(i)>len(s2):
s2=i
print("Longest Word = ",s2)
f1.close()
#Write a python program to read a file line by line store it into vairable
f1=open("abc.txt","r")
s1=""
while True:
s=f1.readline()
if s=="":
break
s1=s1+s
print("Varibale = ",s1)
f1.close()
#Write a python program to read a file line by line store it into list
f1=open("abc.txt","r")
l1=[]
while True:
s1=f1.readline()
if s1=="":
break
l1.append(s1)
print("list =",l1)
f1.close()
#Write a python program to read last n lines
f1=open("abc.txt","r")
n=int(input("Enter Lines"))
lines=f1.readlines()
for i in lines[-n:]:
print(i,end='')
f1.close()
#Write a python program to append text to a file and display the text
f1=open("xyz.txt","w")
f1.write("\nRBNB College Shrirampur")
f1.close()
f1=open("xyz.txt","r")
a=f1.read()
print(a)
f1.close()
#Write a python program to read first n lines
f1=open("kalyani.txt","r")
n=int(input("Enter No of Lines to read"))
for i in range(0,n):
a=f1.readline()
print(a,end="")
f1.close()
#Write a python program to read first n lines
f1=open("kalyani.txt","r")
s=f1.readlines()
n=int(input("Enter no of lines to read"))
for i in range(0,n):
print(s[i],end="")
f1.close()
#Write a python program to print each line of file in reverse order
f1=open("abc.txt","r")
while True:
s=f1.readline()
if s=="":
break
print(s[::-1],end="")
f1.close()
#Write a python program to append text to a file and display the text
f1=open("pqr.txt","w")
f1.write("HIIIIIIII HELLOOOOOO")
a=f1.read()
print(a)
f1.close()
#Write a python program to compute the no.of characters ,words and line in a file
f1=open("kalyani.txt","r")
c1=0
w=0
l=0
while True:
s=f1.readline()
l=l+len(s)
if s=="":
break
c1=c1+1#line count
s1=s.split(" ")
for a in s1:
w=w+1
print("lines=",c1)
print("words=",w)
print("char=",l)
#copy content from one file to another file
f1=open("abc.txt","r")
f2=open("pqr.txt","w")
while True:
s=f1.readline()
if s=="":
break
f2.write(s)
f1.close()
f2.close()
print("File copy succesfully..")
#write text in to file
f1=open("abc.txt","w")
f1.write("Hiii HELLOo")
f1.close()
print("file write succ...")
#read file
f1=open("abc.txt","r")
s=f1.read()
print(s)
f1.close()