Queriesrehnat
Queriesrehnat
no.,Name, Marks).Obtain data from user and write 5 records into the file
import csv
stuwriter=csv.writer(fh)
for i in range(5):
print("student record",(i+1))
name=input("enter name")
stuwriter.writerow(sturec)
import pickle
found=False
fin=open("Stu.dat","rb+")
try:
while True:
stu=pickle.load(fin)
pickle.dump(stu,fin)
found=True
except EOFerror:
if found==False:
else:
print("Record(s)successfully updated.")
import pickle
found=False
try:
print("Searching in FileStudent.csv...")
found=True
except EOFError:
if found==False:
else:
print("search successfull.")
import math
import random
print(str(int(math.pow(random.randint(2,4),2))),end=””)
print(str(int(math.pow(random.randint(2,4),2))),end=””)
print(str(int(math.pow(random.randint(2,4),2)))
Import random
Colurs
=["VIOLET”,”INDIGO”,”BLUE”,”GREEN”,”YELLOW”,”ORANGE”,”RED”]
End=randrange(2)+3
Begin=randrange(End)+1
for i in range(Begin,End):
print(Colours[i],end=”&”)
Q)Write a program to get roll numbers,names,and marks of students of a
class (get from the user)and store these details in a file called
“Student.csv”
fileout=open("Student.csv","w")
for i in range(count):
rollno=int(input("Rollno:"))
name=input("Enter name;")
marks=float(input("Marks:"))
rec=str(rollno)+","+name+","+str(marks)+"\n"
fileout.write(rec)
fileout.close()
Q)Find and write the output of following python code:
def ChangeVal(M,N):
for i in range(N):
if M[i]%5==0:
M[i]//=5
if M[i]%3==0:
M[i]//3
L=[25,8,75,12]
ChangeVal(L,4)
for i in L:
print(i,end="#")
def Change(P,Q=30):
P=P+Q
Q=P+Q
print(P,"#",Q)
return(P)
R=150
S=100
R=Change(R,S)
print(R,"#",S)
S=Change(S)
Q)Write a Python program to open the file hello.txt used in question 6 in
read mode to display its contents .Whta will be the difference if the file
was opened in write mode instead of append mode
f=open("hello.txt","r")
st=""
while st:
st=f.readline()
print(st)
f.close()
Q)Write a program to accept strings/sentences from the user till the user
enters “END” to.Save the data in a text file and then display only those
sentences which begin with an uppercase alphabet
f=open("new.txt","w")
st=""
while st!="END":
f.write(st+"\n")
f.close()
f=open("new.txt","r")
st=""
while st:
st=f.readline()
if st:
if st[0].isupper():
print(st)
f.close()