count_vow = 0
Python Programming count_con = 0
count_low = 0
count_up = 0
count_digit = 0
1 .Read a text file line by line and display each count_other = 0
word separated by a #. print(line)
for ch in line:
if [Link]():
filein = open("[Link]",'r') count_up +=1
line =" " if [Link]():
while line: count_low += 1
line = [Link]() if ch in 'aeiouAEIOU':
count_vow += 1
for w in line: if [Link]():
if w == ' ': count_con += 1
print('#',end = '') if [Link]():
else: count_digit += 1
print(w,end = '') if not [Link]() and ch !=' ' and ch !='\n':
[Link]() count_other += 1
print("Digits",count_digit)
'''
print("Vowels: ",count_vow)
#-------------OR------------------
print("Consonants: ",count_con-count_vow)
filein = open("[Link]",'r') print("Upper Case: ",count_up)
for line in filein: print("Lower Case: ",count_low)
word= line .split() print("other than letters and digit:
for w in word: ",count_other)
print(w + '#',end ='')
[Link]()
print()
[Link]()
'''
[Link] a binary file with the name and roll
2. Read a text file and display the number of number. Search for a given roll number and
vowels/ consonants/ uppercase/ lowercase display the name, if not found display
characters and other than character and digit appropriate message.
in the file.
import pickle
filein = open("[Link]",'r')
#creating the file and writing the data
line = [Link]()
f=open("[Link]", "wb")
srecord={"SROLL":sroll,"SNAME":sname,"SPERC
[Link](["Wakil", 1], f)
":sperc,
[Link](["Tanish", 2], f)
"SREMARKS":sremark}
[Link](["Priyashi", 3], f)
[Link](srecord,Myfile)
[Link](["Kanupriya", 4], f)
[Link](["Aaheli", 5], f)
def Readrecord():
[Link]()
with open ('[Link]','rb') as
#opeining the file to read contents Myfile:
f=open("[Link]", "rb") print("\n-------DISPALY STUDENTS
DETAILS--------")
n=int(input("Enter the Roll Number: "))
print("\nRoll No.",' ','Name','\t',end='')
flag = False
print('Percetage',' ','Remarks')
while True:
while True:
try:
try:
x=[Link](f)
rec=[Link](Myfile)
if x[1]==n:
print(' ',rec['SROLL'],'\t
print("Name: ", x[0]) ' ,rec['SNAME'],'\t ',end='')
flag = True print(rec['SPERC'],'\t
except EOFError: ',rec['SREMARKS'])
break except EOFError:
if flag==False: break
print("This Roll Number does not exist") def Input():
n=int(input("How many records you want to
create :"))
4. Create a binary file with roll number, name
and marks. Input a roll number and update for ctr in range(n):
details. sroll=int(input("Enter Roll No: "))
sname=input("Enter Name: ")
sperc=float(input("Enter Percentage: "))
def Writerecord(sroll,sname,sperc,sremark): sremark=input("Enter Remark: ")
with open ('[Link]','ab') as Writerecord(sroll,sname,sperc,sremark)
Myfile:
with open ('[Link]','wb') as
Myfile:
for j in newRecord:
def Modify(roll):
[Link](j,Myfile)
with open ('[Link]','rb') as
Myfile:
newRecord=[]
while True: def main():
try:
rec=[Link](Myfile) while True:
[Link](rec) print('\nYour Choices are: ')
except EOFError: print('[Link] Records')
break print('[Link] Records')
found=1 print('[Link] Records')
for i in range(len(newRecord)): print('[Link] (Enter 0 to exit)')
if newRecord[i]['SROLL']==roll: ch=int(input('Enter Your Choice: '))
name=input("Enter Name: ") if ch==1:
perc=float(input("Enter Percentage: ")) Input()
remark=input("Enter Remark: ") elif ch==2:
Readrecord()
newRecord[i]['SNAME']=name elif ch==3:
newRecord[i]['SPERC']=perc r =int(input("Enter a Rollno to be update:
"))
newRecord[i]['SREMARKS']=remark
Modify(r)
found =1
else:
else:
break
found=0
main()
if found==0:
5. Remove all the lines that contain the
character `a' in a file and write it to another
print("Record not found") file
#Python program to
# demonstrate stack implementation
# using list
f1 = open("[Link]")
f2 = open("[Link]","w") stack = []
for line in f1:
if 'a' not in line: # append() function to push
[Link](line) # element in the stack
print('## File Copied Successfully! ##') [Link]('a')
[Link]() [Link]('b')
[Link]() [Link]('c')
f2 = open("[Link]","r") print('Initial stack')
print([Link]()) print(stack)
6. Write a random number generator that
generates random numbers between 1 and 6
# pop() function to pop
(simulates a dice).
# element from stack in
# LIFO order
print('\nElements popped from stack:')
import random
min = 1 print([Link]())
max = 6
roll_again = "y" print([Link]())
while roll_again == "y" or print([Link]())
roll_again == "Y":
print("Rolling the
dice...")
val = [Link] (min, print('\nStack after elements are popped:')
max)
print(stack)
print("You get... :", val)
roll_again = input("Roll
the dice again? (y/n)...")
# uncommenting print([Link]())
# will cause an IndexError
[Link] a Python program to implement a
stack using list # as the stack is now empty
8. Create a CSV file by entering user-id and break
password, read and search the password for
given user id
import csv
with open("user_info.csv", "w") as
obj:
fileobj = [Link](obj)
[Link](["User Id",
"password"])
while(True):
user_id = input("enter id:
")
password = input("enter
password: ")
record = [user_id, password]
[Link](record)
x = input("press Y/y to
continue and N/n to terminate the
program\n")
if x in "Nn":
break
elif x in "Yy":
continue
with open("user_info.csv", "r") as
obj2:
fileobj2 = [Link](obj2)
given = input("enter the user id
to be searched\n")
for i in fileobj2:
next(fileobj2)
# print(i,given)
if i[0] == given:
print(i[1])