2025 – INF1511 – ASSESSMENT 7 – QUESTIONS AND ANSWERS
Assessment 7
Started on Sunday, 22 September 2024,
State Finished
Completed on Sunday, 22 September 2024,
Time taken
Marks 15.00/15.00
Grade 100.00 out of 100.00
Question 1
What is the output from the execution of the code?
myLine = 'Python is a great language'
#open the file
myFile='testfile.txt'
f = open(myFile, 'w')
#write or read
f.write('\n%s' %myLine)
#close the file
f.close()
#open the file
f = open(myFile)
#read the file
while True:
line = f.readline()
if len(line) == 0:
break
print (line,)
#close the file
f.close()
a.
Python is a great language
b.
1
, 2025 – INF1511 – ASSESSMENT 7 – QUESTIONS AND ANSWERS
myLine
c.
IO error
d.
syntax error
Question 2
What is the function of the following code?
#comment
nCount=int(input('How may lines? '))
#comment
myFile='testfile.txt'
f = open(myFile, 'a' )
for i in range(0, nCount):
myLine=input('Enter the line : ')
f.write("\n%s" %myLine)
f.close()
a.
to modify lines in a file
b.
to delete lines in a file
c.
to append lines to a file
d.
to select lines in a file
Question 3
What is the output from the execution of the following code?
myFile='testfile.txt'
f = open(myFile, 'r')
2
Assessment 7
Started on Sunday, 22 September 2024,
State Finished
Completed on Sunday, 22 September 2024,
Time taken
Marks 15.00/15.00
Grade 100.00 out of 100.00
Question 1
What is the output from the execution of the code?
myLine = 'Python is a great language'
#open the file
myFile='testfile.txt'
f = open(myFile, 'w')
#write or read
f.write('\n%s' %myLine)
#close the file
f.close()
#open the file
f = open(myFile)
#read the file
while True:
line = f.readline()
if len(line) == 0:
break
print (line,)
#close the file
f.close()
a.
Python is a great language
b.
1
, 2025 – INF1511 – ASSESSMENT 7 – QUESTIONS AND ANSWERS
myLine
c.
IO error
d.
syntax error
Question 2
What is the function of the following code?
#comment
nCount=int(input('How may lines? '))
#comment
myFile='testfile.txt'
f = open(myFile, 'a' )
for i in range(0, nCount):
myLine=input('Enter the line : ')
f.write("\n%s" %myLine)
f.close()
a.
to modify lines in a file
b.
to delete lines in a file
c.
to append lines to a file
d.
to select lines in a file
Question 3
What is the output from the execution of the following code?
myFile='testfile.txt'
f = open(myFile, 'r')
2