Python Files Quiz
By Mickey Arnold
starstarstarstarstarstarstarstarstarstar
Last updated 10 months ago
10 Questions
1 point
1
Question 1
1.
What is the output?
file = open('input1.dat', 'r')
for line in file: print ( line )
///////////////////////////input1.datIwantadog
What is the output?
file = open('input1.dat', 'r')
for line in file:
print ( line )
///////////////////////////
input1.dat
I
want
a
dog
1 point
1
Question 2
2.
What is the output?
file = open('input2.dat', 'r')for line in file: print ( line )
//////////////////////////////input2.dat21billwatt1943
What is the output?
file = open('input2.dat', 'r')
for line in file:
print ( line )
//////////////////////////////
input2.dat
21
bill
watt
1943
1 point
1
Question 3
3.
file = open('input3.dat', 'r')times = int(file.readline().strip())for x in range(0, times): line = file.readline() print ( line )///////////////////////////////////input3.dat8twothreefourfive
From the code above, what is times?
file = open('input3.dat', 'r')
times = int(file.readline().strip())
for x in range(0, times):
line = file.readline()
print ( line )
///////////////////////////////////
input3.dat
8
two
three
four
five
From the code above, what is times?
1 point
1
Question 4
4.
file = open('input3.dat', 'r')times = int(file.readline().strip())for x in range(0, times): line = file.readline() print ( line )///////////////////////////////////input3.dat3twothreefourfive
From the code above, what is the output?
file = open('input3.dat', 'r')
times = int(file.readline().strip())
for x in range(0, times):
line = file.readline()
print ( line )
///////////////////////////////////
input3.dat
3
two
three
four
five
From the code above, what is the output?
1 point
1
Question 5
5.
file = open('input4.dat', 'r')times = int(file.readline().strip())total = 0for x in range(0, times): num = int(file.readline()) total = total + numprint ( "total = " + str(total) )
//////////////////////////////////////input4.dat8 1215213634829923
what is the output?
file = open('input4.dat', 'r')
times = int(file.readline().strip())
total = 0
for x in range(0, times):
num = int(file.readline())
total = total + num
print ( "total = " + str(total) )
//////////////////////////////////////
input4.dat
8
12
15
21
36
34
82
99
23
what is the output?
1 point
1
Question 6
6.
file = open('input4.dat', 'r')times = int(file.readline().strip())total = 0for x in range(0, times): num = int(file.readline()) total = total + numprint ( "total = " + str(total) )
//////////////////////////////////////input4.dat4 1215213634829923
what is the output?
file = open('input4.dat', 'r')
times = int(file.readline().strip())
total = 0
for x in range(0, times):
num = int(file.readline())
total = total + num
print ( "total = " + str(total) )
//////////////////////////////////////
input4.dat
4
12
15
21
36
34
82
99
23
what is the output?
1 point
1
Question 7
7.
file = open('input4.dat', 'r')times = int(file.readline().strip())total = 0for x in range(0, times): num = int(file.readline()) total = total + numprint ( "total = " + str(total) )
//////////////////////////////////////input4.dat1215213634829923
what is times?
file = open('input4.dat', 'r')
times = int(file.readline().strip())
total = 0
for x in range(0, times):
num = int(file.readline())
total = total + num
print ( "total = " + str(total) )
//////////////////////////////////////
input4.dat
12
15
21
36
34
82
99
23
what is times?
1 point
1
Question 8
8.
The program sends data to the file in the output file stream. Then the program gets data from the file. The program is not always in control when working with files.
The program sends data to the file in the output file stream. Then the program gets data from the file. The program is not always in control when working with files.
1 point
1
Question 9
9.
For loops and While loops are used to __________through loops.
1 point
1
Question 10
10.
What is output by the code below?cat = "QR S T UV"dog = cat.split( )print( dog[3] )
What is output by the code below?
cat = "QR S T UV"
dog = cat.split( )
print( dog[3] )