File Organisation
File Organisation
CODES...
def create():
f=open('file.txt','w')
for i in range(n):
f.write(s+'\n')
f.close()
create()
def size():
f=open('file.txt','r')
s=f.read()
f.close()
# To find no. of lines in files...
def num():
f=open('file.txt','r')
s=f.readlines()
f.close()
def line():
f=open('file.txt','r')
s=f.readlines()
for i in s:
print(i)
f.close()
def words():
f=open('file.txt','r')
s=f.read()
d=s.split()
c=0
for i in d:
print(i)
c+=1
f.close()
def vowels():
f=open('file.txt','r')
s=f.read()
c=0
for i in s:
if i in 'AEIOUaeiou':
c+=1
f.close()
def consonant():
f=open("file.txt")
s=f.read()
c=0
for i in s:
if i.isalpha():
if i not in "AEIOUaeiou":
c+=1
f.close()
def digits():
f=open('file.txt','r')
s=f.read()
c=0
for i in s:
if i.isdigit():
c+=1
f.close()
def alphabets():
f=open("file.txt",'r')
s=f.read()
c=0
for i in s:
if i.isalpha():
c+=1
f.close()
def lcase():
f=open('file.txt','r')
s=f.read()
c=0
for i in s:
if i.isalpha():
if i.islower():
c+=1
f.close()
def first():
f=open('file.txt','r')
s=f.readlines()
f.close()
# To print last line of file...
def last():
f=open('file.txt','r')
s=f.readlines()
f.close()
def dig():
f=open('file.txt','r')
s=f.readlines()
for i in s:
if i[0].isdigit():
print(i)
else:
break
f.close()
f=open('file.txt','r')
s=f.read()
c=0
for i in s.split():
if i=='This':
c+=1
f.close()
def alnum():
f=open('file.txt','r')
s=f.read()
for i in s:
if i.isalnum():
print(i)
f.close()
def display():
f=open('file.txt','r')
s=f.readlines()
for i in s:
if i[0].isdigit():
continue
else:
print(i)
f.close()
def copy():
f=open('file.txt','r')
f1=open('info.txt','w')
s=f.readlines()
for i in s:
f1.write(i)
f1.close()
f.close()
def capitalize():
f=open('file.txt','r')
s=f.readlines()
for i in s:
i=i.title()
print(i)
f.close()
def start():
f=open('file.txt','r')
s=f.readlines()
for i in s:
if i[0]not in 'pP':
print(i)
f.close()
def starting():
f=open('file.txt','r')
s=f.readlines()
c=0
for i in s:
if i[0] in 'sS':
print(i)
c+=1
print("Total numbers of required lines : ",c)
f.close()
# MENU...
while True:
if a==1:
size()
elif a==2:
num()
elif a==3:
line()
elif a==4:
words()
elif a==5:
vowels()
elif a==6:
consonant()
elif a==7:
digits()
elif a==8:
alphabets()
elif a==9:
lcase()
elif a==10:
first()
elif a==11:
last()
elif a==12:
dig()
elif a==13:
this()
elif a==14:
alnum()
elif a==15:
display()
elif a==16:
copy()
elif a==17:
capitalize()
elif a==18:
start()
elif a==19:
starting()
else:
break
if restart=='y':
pass
elif restart=='n':
break
else:
print("value unacceptable")
print("exiting")
break
OUTPUTS...
Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun 6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)]
on win32
= RESTART: C:\Users\dixit\AppData\Local\Programs\Python\Python312\file.py
Enter line : python has dynamic typing and automatic memory management.
Enter line : some features of python are interpreted language, portability and readability.
Number of lines : 5
Python
is
high
level
programing
language.
it
was
created
by
Guido
Van
Rossum.
1991
was
the
year
when
it
was
released.
python
has
dynamic
typing
and
automatic
memory
management.
some
features
of
python
are
interpreted
language,
portability
and
readability.
Number of vowels : 80
Number of digits : 4
Last line : some features of python are interpreted language, portability and readability.
P,y,t,h,o,n,i,s,a,h,i,g,h,l,e,v,e,l,p,r,o,g,r,a,m,i,n,g,l,a,n,g,u,a,g,e,i,t,w,a,s,c,r,e,a,t,e,d,b,y,G,
u,i,d,o,V,a,n,R,o,s,s,u,m,1,9,9,1,w,a,s,t,h,e,y,e,a,r,w,h,e,n,i,t,w,a,s,r,e,l,e,a,s,e,d,p,y,t,h,o
,n,h,a,s,d,y,n,a,m,i,c,t,y,p,i,n,g,a,n,d,a,u,t,o,m,a,t,i,c,m,e,m,o,r,y,m,a,n,a,g,e,m,e,n,t,s,o,
m,e,f,e,a,t,u,r,e,s,o,f,p,y,t,h,o,n,a,r,e,i,n,t,e,r,p,r,e,t,e,d,l,a,n,g,u,a,g,e,p,o,r,t,a,b,i,l,i,t,y,a,
n,d,r,e,a,d,a,b,i,l,i,t,y,Do you want to perform again? (y/n) : y
ANSHIKA DIXIT
CLASS= XII-B
ROLL NO.=11