1.
Read a text file line by line and display each word separated by a #
def write():
with open('[Link]','w') as mf:
content=input('Enter the content:')
[Link](content)
def display():
with open('[Link]','r') as mf:
f=[Link]()
print('--------------------------------------------------')
print('The Formatted Text-')
for line in f:
for word in [Link]():
print(word,end='#')
write()
display()
2. Create a binary file with name and roll number. Search for a given roll number and display the name, if not found
display appropriate message.
import pickle
with open("[Link]",'wb+') as mf:
rec={}
found=False
n=int(input('Enter how many student details you want to enter:'))
for i in range(n):
rno=int(input('Enter rollno.'))
name=input('Enter name:')
rec['Roll']=rno
rec['name']=name
[Link](rec,mf)
[Link](0)
c=int(input('Enter the rollno to search:'))
try:
while True:
b=[Link](mf)
if b['Roll']==c:
print(b)
found=True
except EOFError:
if found==False:
print('File not found')
3. Write a python program to create a stack called Employee, to perform basic operations onStack using a list which
contains two values-employee number and employee name. The program should include the options for addition,
deletion, and display of employee details.
employee=[]
c='yes'
print('[Link]\[Link]\[Link]\[Link]')
while [Link]()=='yes':
print('')
ch=int(input('Enter your choice:'))
print('')
if ch==1:
em_id=int(input("Enter employee number:"))
e_name=input("Enter employee name:")
emp=(em_id,e_name)
[Link](emp)
elif ch==2:
if employee==[]:
print("Stack Empty")
else:
em_id,e_name=[Link]()
print("The Deleted List Element is:",em_id,e_name)
elif ch==3:
i=len(employee)
while i>0:
print(employee[i-1])
i=i-1
elif ch==4:
print("Logging out session over")
break
else:
print("Wrong choice it doesnt exist")
c=input("Do you want to try again?(yes/no):")
4. To write a Python program Create a CSV file to store Empno, Name, Salary and search any Empno and display
Name, Salary and if not found display appropriate message.
import csv
def create():
with open("[Link]",'w',newline='')as mf:
w=[Link](mf)
c='yes'
while [Link]()=='yes':
e_id=int(input("Enter employee ID:"))
e_name=input("Enter employee name:")
e_sal=float(input("Enter salary:"))
l=[e_id,e_name,e_sal]
[Link](l)
c=input("Do you want to continue?(yes/no):")
def search():
with open('[Link]','r',newline='\r\n') as mf:
no=int(input('Enter employee ID to search:'))
found=0
row=[Link](mf)
for dat in row:
if dat[0]==str(no):
print('\nEmployee details-')
print('=====================')
print('Name:',dat[1],'\nSalary:',dat[2])
found=1
break
if found==0:
print('employee number not found :(')
create()
search()