1.
Experiment :-
file=open('[Link]','r')
lines=[Link]()
for line in lines:
words=[Link]()
for word in words:
print(word+'#',end='')
print('')
[Link]()
2. Experiment :-
a=open('[Link]').read()
v=c=b=u=0
print('input file data contains:',a)
for i in a:
if [Link]() in 'aeiou':
v+=1
elif [Link]() not in 'aeiou':
c+=1
else:
continue
for i in a:
if [Link]():
b+=1
elif [Link]():
continue
elif [Link]():
u+=1
else:
continue
print('[Link] vowels:',v)
print('[Link] consonants:',c)
print('[Link] lowercase:',b)
print('[Link] uppercase:',u)
[Link]:-
a=open('[Link]').read()
g=open('[Link]','w')
print('input file data:',a)
for i in a:
if i not in 'aA':
[Link](i)
[Link]()
o=open('[Link]').read()
print('output file data:',o)
[Link]:-
def generate_fibonacci(n):
fibonacci_series=[0,1]
while len(fibonacci_series)<n:
nxt_value= fibonacci_series[-1]+fibonacci_series[-2]
fibonacci_series.append(nxt_value)
return fibonacci_series
num_terms= int(input('enter the [Link] terms in the fibonacci
series:'))
fibo_series=generate_fibonacci(num_terms)
print('fibonacci series:',fibo_series)
[Link]:-
import pickle
def write():
f=open('[Link]','wb')
record=[]
while True:
rno=int(input('enter the rolll no:'))
name=input('enter your name:')
marks=int(input('enter your marks:'))
d=[rno,name,marks]
[Link](d)
ch=input('do you want to enter more records?(y/n)')
if ch=='n':
break
[Link](record,f)
print('records written successfully')
[Link]()
def search():
f=open('[Link]','rb')
s=[Link](f)
print(s)
rno=int(input('enter the rollno to be searched'))
for i in s:
if i[0]==rno:
print('record found successfully')
print(i)
def read():
f=open('[Link]','rb')
s=[Link](f)
for i in s:
print(i)
write()
search()
read()
[Link]:-
import pickle
def write():
f=open('[Link]','wb')
rec=[]
while True:
rno=int(input('enter the roll no:'))
name=input('enter the name:')
marks=int(input('enter the marks:'))
d=[rno,name,marks]
[Link](d)
ch=input('do you want to enter more records (Y/N)?')
if ch in'nN':
break
else:
continue
[Link](rec,f)
def update():
f=open('[Link]',"rb+")
s=[Link](f)
rno=int(input('enter the roll no to be updated:'))
for i in s:
if rno==i[0]:
print('current name:',i[1])
i[1]=input('enter the new name:')
[Link](0)
[Link](s,f)
def read():
f=open('[Link]','rb')
d=[Link](f)
for i in d:
print(i,'\n',end='')
write()
update()
read()
[Link]:-
import csv
def add():
f=open('[Link]','w',newline="")
mwriter=[Link](f)
[Link](['name','roll no'])
rec=[]
while True:
rno=int(input('enter your roll no:'))
name=input('enter your name:')
data=[rno,name]
[Link](data)
ch=input('do you want to enter more records (Y/N)?')
if ch in'nN':
break
[Link](rec)
[Link]()
def extract():
a=open('[Link]','r')
b=input('enter rno to be searched:')
sreader=[Link](a)
for i in sreader:
if i[0]==b:
print(i)
add()
extract()
[Link]:-
L=list(eval(input('enter the list of elements:')))
def max_check():
print('maximum of the list:',max(L))
def min_check():
print('minimum of the list:',min(L))
def sum_check():
print('sum of the elements in list:',sum(L))
max_check()
min_check()
sum_num()
[Link]:-
L=list(eval(input('enter the list of elements:')))
def max_check():
print('maximum of the list:',max(L))
def min_check():
print('minimum of the list:',min(L))
def sum_check():
print('sum of the elements in list:',sum(L))
max_check()
min_check()
sum_num()
def palin(s):
returns==s[::-1]
def countchar(s,c):
return [Link](c)
def rep(s,t,u):
return [Link](t,u)
while True:
d=int(input('enter the choice:1,2,3:'))
if d==1:
a=input('enter a string'(
if palin(a)==True:
print('palindrome')
else:
print('not a palindrome')
elif d==2:
b=input('enter the char to count')
print(countchar(b))
elif d==3:
e=input('enter a string')
r=input('enter a existing char')
n=input('enter new char')
print(rep(e,r,n))
ch=input('y/n')
if ch in'nN':
break
else:
continue
palin(e)
countchar(r)
rep(e,r,n)
[Link]:-