Question: You have to create a program that writes the numbers - 5 , 2 and 3 to a file output.txt , then later reads this
You have to create a program that writes the numbers and to a file output.txt then later reads this file, sums the numbers, and then adds the sum back to the file. Which code applies write and read methods appropriately to perform this task?
data
fout opendataoutput.txtw
for val in data:
fout.writestrval
fout.close
data
fin opendataoutput.txtr
for values in fin:
val values.replace
dataappendval
fin.close
sum sumdata
mysum opendataoutput.txtw
fout.writestrmysum
fout.close
data
fout opendataoutput.txtr
for val in data:
fout.writeval
fout.close
data
fin opendataoutput.txtw
for values in fin:
val values.replace
dataappendintval
fin.close
mysum sumdata
fout opendataoutput.txta
fout.writestrmysum
fout.close
data
fout opendataoutput.txtw
for val in data:
fout.writestrval
fout.close
data
fin opendataoutput.txtr
for values in fin:
val values.replace
dataappendintval
fin.close
mysum sumdata
fout opendataoutput.txta
fout.writestrmysum
fout.close
data
fout opendataoutput.txtr
for val in data:
fout.writestrval
fout.close
data
fin opendataoutput.txtw
for values in fin:
val values.replace
dataappendintval
fin.close
mysum sumdata
fout opendataoutput.txta
fout.writestrmysum
fout.close
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
