Professional Documents
Culture Documents
Python Imp Programs
Python Imp Programs
list1=[5,7,9,15,17]
primelist=[]
for i in list1:
flag=0
for j in range(2,i):
if(i%j==0):
flag=1
if(flag==1):
continue
else:
primelist.append(i)
print(primelist)
13.write a program which copy the alternate characters from one file
into another file.
f1=open('count_fre.py','r')
data=f1.read()
f2=open("akash.txt","w")
for i in range(0,len(data),2):
f2.write(data[i])
14.Accept any file and replace all uppercase with lowercase and
viseversa,and replace all digits with 0 ,and replace special symbols
with $.
filename=input("Enter any filename=")
f1=open(filename,'r')
f2=open('asch.txt','r+')
data=f1.read()
for i in data:
if(i.isupper()):
f2.write(i.lower())
elif(i.islower()):
f2.write(i.upper())
elif(i.isdigit()):
f2.write('0')
elif(i.isspace()):
continue
else:
f2.write('$')
data2=f2.read()
print(data2)
f2=open("akash.txt","a")
f2.write("\nfrom ahmednagar")
f2.close()
f3=open("akash.txt","r")
print(f3.read())
f3.close()
except invalidage as x:
None