selfstudys_com_file (2)
selfstudys_com_file (2)
Q. No Part A Marks
import math
import random
print(math.ceil(random.random()))
1. load ()
2. pow ()
1. sqrt()
2. dump()
QUESTIONS ON TEXT FILE HANDLING
f1=open("mydata","a")
______#blank1
f1.close()
(i)what type of file is mydata
(ii) Fill in the blank1 with statement to write "abc" in the file "mydata"
Line1\n
\n
line3
Line 4
\n
line6
What would be the output of following code?
16 In which of the following file modes the existing data of the file will not 2
be lost?
i) rb
ii) w
iii) a+b
iv) wb+
v) r+
vi) ab
vii) w+b
viii)wb
ix) w+
ANSWERS
9 def countwords():
S=open(“Mydata”, “r”)
f=S.read()
z=f.split()
count=0
for I in z:
count=count+1
print(“Total number of words”,count)
10 def write1():
f = open("myfile.txt","w")
while True:
line = input("Enter line")
f.write(line)
choice = input("Are there more lines")
if choice == "N":
break
f.close()
11 fin=open("file1.txt")
fout=open("file2.txt","w")
data=fin.read()
fout.write(data)
fin.close()
fout.close()
12 d) f.readlines()
14 i) Text file
ii) f1.write(“abc”)
15 Line1
Line3
Line 6
Line 4
16 ab and a+b mode
17 a) string b)string c)string d)list
Q.3 One row of CSV file can be considered as _______ in terms of database
ANS Record
Q5 A _____ function allows to write a single record into each row in CSV file.
ANS writerow()
ANS readline()
ANS writerrows()
1. Open()
2. reader()
3. writer()
4. writerow()
5. close()
ANS True