Computer Project
Computer Project
NH – 34 Shimuldhab, Dhumadighi
Malda
f=open(r"C:\Users\user\Documents\Test.txt")
data=f.read()
a=data.split()
for i in a :
print(i+'#',end = '')
OUTPUT
2. Read a text file and display the number of
vowels/consonants/uppercase/lower-
case characters in the file
f=open(r'C:\Users\user\Documents\Test.txt')
data=f.read()
print(data)
print(" ")
vc=0
cc=0
uc=0
lc=0
for i in data:
if i.isalpha():
if i in 'AEIOUaeiou':
vc+=1
else:
cc+=1
if i.isupper():
uc+=1
if i.islower():
lc+=1
print("No.of Vowels in the file are:",vc)
print("No.of Consonants in the file are:",cc)
print("No. of uppercase characters in the file are:",uc)
print("No. of lowercase characters in the file are:",lc)
OUTPUT
3. Remove all the lines that contain the
character “a” in a file and write it to
another file
f=open(r'C:\Users\user\Documents\Test.txt')
data=f.readlines()
for i in data:
print(i)
f1=open(r'C:\Users\user\Documents\Test.txt','w')
f2=open(r'C:\Users\user\Documents\Test1.txt','w')
for i in data:
if 'a' in i:
f2.write(i)
else:
f1.write(i)
f1.close()
f2.close()
OUTPUT
f=open('Student.dat','rb')#rec=[[1,'priya',50],[2,'preeti',60]]
found=0
try:
while True:
rec=pickle.load(f)
srn=int(input("Enter the new marks:"))
i[2]=smks
print("The updated record of the student is:",1)
found=1
break
except:
f.close()
if found==0:
print("No such record")
OUTPUT
while True:
ch=int(input("Enter 1 to Roll the dice and any other key to exit..."))
if ch==1:
print('Dice:',random())
else:
print("Game Over")
break
OUTPUT
def pop_element():
if not stack:
print("stack is empty!")
else:
e=stack.pop()
print("removed element:",e)
print(stack)
while True:
print("select the operation 1.push 2.pop 3.quit")
choice = int(input())
if choice==1:
push()
elif choice==2:
pop_element()
elif choice==3:
break
else:
print("Enter the correct operation!")
OUTPUT