What is the output?
file = open('input1.dat', 'r')
for line in file:
print ( line )
///////////////////////////
input1.dat
I
want
a
dog
What is the output?
file = open('input2.dat', 'r')
for line in file:
print ( line )
//////////////////////////////
input2.dat
21
bill
watt
1943
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?
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?
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?
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?
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?
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.
What is output by the code below?
cat = "QR S T UV"
dog = cat.split( )
print( dog[3] )