Practice Python Programs 2024
Practice Python Programs 2024
while True:
f.write(line+'\n')
print()
a = input('Press y to continue:')
if a != 'y':
break
f.close()
uc = lc = d = 0
r = f.read()
for i in r:
uc+=1
elif i.islower():
lc+=1
if i.isdigit():
d+=1
print('Frequency of Digits:' , d)
f.close()
"""2) WAP to create a csv file with the following data given below. Read that file and display data
stored in that file.
1st record should be PID, PNAME , COST , QUANTITY. sample of product.csv file is given below.
P3 , Comb , 40 , 300
P5 , Pen , 10 , 250"""
import csv
w = csv.writer(f)
])
f.close()
r = csv.reader(f)
for i in r:
print(i)
f.close()
#3) WAP to create a binary file. Store Name , Roll No & Percentage of a student using pickle module.
Display contents of the file
import pickle
i=1
while True:
p = float(input('Enter Percentage:'))
pickle.dump(d,f)
a = input('Press y to continue:')
if a != 'y':
break
f.close()
try:
while True:
r = pickle.load(f)
print(r)
except:
f.close()
#4) WAP to create a text file. Display frequency of words 'the' & 'The' in it.
while True:
l = input('Enter a line:')
f.write(l+'\n')
print()
a = input('Press y to continue:')
if a != 'y':
break
f.close()
s = r.split()
t1 = t2 = 0
for i in s:
if i == 'the':
t1+=1
if i=='The':
t2+=1
f.close()
#5) WAP to perform push and pop operations in a stack implemented as list
stk.append(item)
if len(stk) == 0:
print('Error!\nStack UnderFlow')
else:
i = stk.pop()
if len(stk) == 0:
print('Stack Empty')
else:
top = len(stk) - 1
if i == top:
else:
print(stk[i])
#__main__
stack = []
top = len(stack) -1
while True:
print('Stack Operations\n1)Push\n2)Pop\n3)Display\n4)Exit')
a = int(input('Choose(1-4):'))
if a == 1:
elif a == 2:
pop(stack)
elif a==3:
Display(stack)
elif a == 4:
break
else:
while True:
l = input('Enter a line:')
f.write(l+'\n')
print()
a = input('Press y to continue:')
if a != 'y':
break
f.close()
v=c=0
r = f.read()
for i in r:
if i in 'aeiouAEIOU':
v+=1
else:
c+=1
f.close()