#Type C Question
#Question No 1:
file1=open("Eris.txt",'r')
file2=open("New.txt",'w')
lst=file1.readlines()
for i in lst:
words=i.split()
file2.write('*',join(word))
file2.write('\n')
file2.close()
file1.close()
#Question No 2:
def portal:
file1=open("Eris.txt",'r')
file2=open("New.txt",'w')
lst=file1.readlines()
for i in lst:
print(i[ : 9 ])
if i [: 9] =="Atheletics":
file2.write(i)
file2.close()
file1.close()
#Question No 3:
print("Name\t|\tPhone no. ")
file = open("Eris.txt", "r")
lst = file.readlines()
for i in lst :
data = i.split()
print( data[0] ,end = "\t" )
print("|" , end = "\t")
print ( data[1] )
file.close()
#Question No 4:
to_no = 0
the_no = 0
file = open("Poem.txt", "r")
lst = file.readlines()
for i in lst :
word = i.split()
for j in word :
if j == "to" or j == "To" :
to_no += 1
elif j == "the" or j == "The" :
the_no += 1
print("Number 'to' : " , to_no)
print("Number 'the' : " , the_no)
file.close()
#Question No 5:
def AMCount( ):
f = open("STORY.txt", "r",)
data = f.read()
count_a = 0
count_m = 0
for i in data :
if i == "a" or i == "A":
count_a += 1
elif i == "m" or i == "M":
count_m += 1
print("A or a :", count_a )
print("M or m:", count_m)
AMCount()
#Question No 6:
count = 0
file = open("Article.txt","r")
sen = file.read()
for i in range ( len(sen) ) :
if sen[ i ].isupper() :
count += 1
print("Number of upper case alphabet : ", count)
file.close()
#Question No 7:
file1 = input("Enter the name of original file :- ")
file2 = input("Enter the name of New file :- : ")
old = open( file1 , "r")
new = open( file2, "w")
data = old.read()
new.write( data )
print(" Program run successfully ")
old.close()
new.close()
#Question No 8:
file1 = input("Enter the name of file which you want to append : ")
file2 = input("Enter the name of original file : ")
old = open( file2 , "r" )
new = open( file1 , "a" )
data = old.read()
new.write( "\n" + data)
print("Program run successfully ")
old.close()
new.close()
#Question No 9:
def DISPLAYWORDS() :
file = open("story.txt", "r")
lst = file.readlines()
for i in lst :
word = i.split()
for j in word :
if len( j ) < 4 :
print( j )
file.close()
print("Word with length smaller than 3 :- \n")
DISPLAYWORDS()
#Question No 10:
upper = open("UPPER.txt","w")
lower = open("LOWER.txt" , "w" )
other = open ("OTHER.txt" , "w")
while True :
user = input("Enter a charracter (for exit enter quit ): ")
if user == "quit" or user == "Quit" :
break
elif user.isupper() :
upper.write( user + " " )
elif user.islower( ) :
lower.write( user + " " )
else :
other.write( user + " " )
upper.close()
lower.close()
other.close()
#Question No 11:
count = 0
file = open("LINES.txt","r")
lst = file.readlines()
for i in lst :
if i[ 0 ] == "A" :
print(i)
count += 1
print()
print("So for number of sentences started with A : ",count)
file.close()
#Question No 12:
file = open("Pathwala.txt","r")
data = file.readlines()
for i in range( len( data ) ):
for j in range( len( data[ i ] ) ):
if data [ i ][ j ] == "$" :
break
print( "Total number of characters up to the first $ befor = ",i+j )
file.close()
#Question No 13:
import pickle
file = open("member.dat","wb")
while True :
dic={}
no = int(input("Enter memberbno. :-"))
name = input("Enter name:-")
dic[ "Memberno."] = no
dic["Name"] = name
pickle.dump( dic, file )
user = input("For quit enter quit :-")
if user == "quit":
break
print("Thankyou")
file.close()
#Question No 14:
import pickle
file = open("member.dat","wb")
while True :
dic={}
no = int(input("Enter memberbno. :-"))
name = input("Enter name:-")
dic[ "Memberno."] = no
dic["Name"] = name
pickle.dump( dic, file )
user = input("For quit enter quit :-")
if user == "quit":
break
file.close()
#Question No 15:
import pickle
file = open("staff.dat", "rb")
found = 0
try :
while True :
staff = pickle.load(file)
if staff [ "Staff Code" ] == 'S0105':
print(staff)
found=1
except EOFError :
if found == 0:
print("Not found !!!")
file.close()
#Question No 16:
import pickle
file = open("COMPANY.DAT","rb")
found = 0
try :
while True :
Company = pickle.load(file)
if Company [ "CompID" ] == '1005':
print(Company)
found=1
except EOFError :
if found == 0:
print("Not found !!!")
file.close()
#Question No 17:
import pickle
def search() :
file = open("TRAIN.DAT","rb")
found = 0
try :
while True :
Train = pickle.load(file)
if Train [ "To" ] == 'Delhi':
print(Train)
found=1
except EOFError :
if found == 0:
print("Not found !!!")
file.close()
search()
#Question No 18:
import pickle
def CreateFile():
f = open("Book.dat", "wb")
while True :
num = int(input("Enter Book Number :- "))
name = input ("Enter Book Name :- ")
aut = input("Enter Author :- ")
pri = float(input("Enter Price of Book :- "))
lst= [ num, name, aut, pri]
pickle.dump( lst, f)
choice = input("For exit (Enter exit):- ")
print()
if choice == "exit" or choice == "Exit":
print("Thank you")
print()
break
f.close()
def CoutRec():
print("For Searching -")
aut = input("Enter Author :- ")
f = open("Book.dat", "rb")
count = 0
try :
while True:
data = pickle.load(f)
if data[2] == aut :
count += 1
except EOFError:
f.close()
print("Number of Book with Author name", aut , "=", count)
CreateFile()
CoutRec()
#Question No 19:
import pickle
f = open("NOTES.dat", "rb")
try :
while True:
line = pickle.load(f)
word = line.split()
if len( word ) == 5 :
print( line )
except EOFError:
f.close()
#Question No 20:
import csv
file = open( "Pathwalla.txt","r" )
data = csv.reader(file, delimiter = "|")
for i in data :
print(i)
file.close()
#Question No 21:
import csv
file = open( "Pathwalla.txt","r+" )
lst = eval(input("Enter a nested list :-"))
path_write = csv.writer( file)
path_write.writerows( lst )
data = csv.reader(file)
for i in data :
print(i)
file.close()
#Question No 23:
import csv
def Pathwalla( file1 ):
file2 = open( "Portalexpress.txt","w",newline="" )
portal_write = csv.writer( file2 , delimiter = "|")
data = csv.reader(file1)
for i in data :
if i[0][:5] != "check" :
portal_write.writerow( i )
file2.close()
file1 = open( "Pathwalla.txt","r" )
Pathwalla( file1 )
print ("Thank You !!")