0% found this document useful (0 votes)
8 views8 pages

programs (1)

Programs of computer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

programs (1)

Programs of computer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1.

Experiment :-
file=open('exp1.txt','r')
lines=file.readlines()
for line in lines:
words=line.split()
for word in words:
print(word+'#',end='')
print('')
file.close()

2. Experiment :-

a=open('exp2.txt').read()
v=c=b=u=0
print('input file data contains:',a)
for i in a:
if i.lower() in 'aeiou':
v+=1
elif i.lower() not in 'aeiou':
c+=1
else:
continue
for i in a:
if i.islower():
b+=1
elif i.isspace():
continue
elif i.isupper():
u+=1
else:
continue

print('no.of vowels:',v)
print('no.of consonants:',c)
print('no.of lowercase:',b)
print('no.of uppercase:',u)
3.Experiment:-

a=open('exp3.txt').read()
g=open('exp3opf.txt','w')
print('input file data:',a)
for i in a:
if i not in 'aA':
g.write(i)
g.close()
o=open('exp3opf.txt').read()
print('output file data:',o)

4.experiment:-

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 no.of terms in the fibonacci
series:'))
fibo_series=generate_fibonacci(num_terms)
print('fibonacci series:',fibo_series)

5.experiment:-

import pickle
def write():
f=open('binaryfile.dat','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]
record.append(d)
ch=input('do you want to enter more records?(y/n)')
if ch=='n':
break
pickle.dump(record,f)
print('records written successfully')
f.close()

def search():
f=open('binaryfile.dat','rb')
s=pickle.load(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('binaryfile.dat','rb')
s=pickle.load(f)
for i in s:
print(i)

write()
search()
read()

6.Experiment:-

import pickle
def write():
f=open('binaryfile.dat','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]
rec.append(d)
ch=input('do you want to enter more records (Y/N)?')
if ch in'nN':
break
else:
continue
pickle.dump(rec,f)

def update():
f=open('binaryfile.dat',"rb+")
s=pickle.load(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:')
f.seek(0)
pickle.dump(s,f)

def read():
f=open('binaryfile.dat','rb')
d=pickle.load(f)
for i in d:
print(i,'\n',end='')

write()
update()
read()

7.experiment:-

import csv
def add():
f=open('students.csv','w',newline="")
mwriter=csv.writer(f)
mwriter.writerow(['name','roll no'])
rec=[]
while True:
rno=int(input('enter your roll no:'))
name=input('enter your name:')
data=[rno,name]
rec.append(data)
ch=input('do you want to enter more records (Y/N)?')
if ch in'nN':
break
mwriter.writerows(rec)

f.close()
def extract():
a=open('students.csv','r')
b=input('enter rno to be searched:')
sreader=csv.reader(a)
for i in sreader:
if i[0]==b:
print(i)

add()
extract()

8.Experiment:-

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()

9.Experiment:-

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 s.count(c)
def rep(s,t,u):
return s.replace(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)

11.Experimenet:-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy