Q2. Program to store rollno and name of 6 student in csv file .f=open("r.txt","w") for i in range(6): roll=input("enter roll") name=input("enter name") f.write(roll) f.write(name) f.close() >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter roll1 enter nameram enter roll2 enter namesham enter roll3 enter namegeeta enter roll4 enter nameseema enter roll5 enter namefina enter roll6 enter namerama
Q3.Program to store rollno and name of 6 student in binary fileimport csv f=open("r.csv","w") for i in range(6): roll=input("enter roll") name=input("enter name") f.write(roll) f.write(name) f.close() >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter roll1 enter namerama enter roll2 enter namedeepa enter roll3 enter namegeeta enter roll4 enter namereema enter roll5 enter namefeena enter roll6 enter namegeeta
Q4.Program to print even number in text fileimport pickle f=open("r.dat","wb") for i in range(6): roll=int(input("enter rollno")) name=input("enter name") s={"roll":roll,"name":name} pickle.dump(s,f) f.close() enter rollno1 enter nameram enter rollno2 enter namesham enter rollno3 enter namegeeta enter rollno4 enter nametimm enter rollno5 enter namemamta enter rollno6 enter nameseema
Q5 Program to print odd number in text filef=open("rt.txt",'w') for i in range(2,10): if(i%2==0): f.write(str(i)) f.close() file output 2468
f=open("rt.txt",'w') for i in range(2,10): if(i%2==0): None else: f.write(str(i)) f.close() file Output 3579
0 Comments