Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 -5,2 and 3 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?
data1=[-5,2,3]
fout = open('data_output.txt','w')
for val in data1:
fout.write(str(val)+"
")
fout.close()
data2=[]
fin = open('data_output.txt','r')
for values in fin:
val = values.replace("
","")
data2.append(val)
fin.close()
sum = sum(data2)
mysum = open('data_output.txt','w')
fout.write(str(mysum ))
fout.close()
data1=[-5,2,3]
fout = open('data_output.txt','r')
for val in data1:
fout.write(val +"
")
fout.close()
data2=[]
fin = open('data_output.txt','w')
for values in fin:
val = values.replace("
","")
data2.append(int(val))
fin.close()
mysum = sum(data2)
fout = open('data_output.txt','a')
fout.write(str(mysum ))
fout.close()
data1=[-5,2,3]
fout = open('data_output.txt','w')
for val in data1:
fout.write(str(val)+"
")
fout.close()
data2=[]
fin = open('data_output.txt','r')
for values in fin:
val = values.replace("
","")
data2.append(int(val))
fin.close()
mysum = sum(data2)
fout = open('data_output.txt','a')
fout.write(str(mysum ))
fout.close()
data1=[-5,2,3]
fout = open('data_output.txt','r')
for val in data1:
fout.write(str(val)+"
")
fout.close()
data2=[]
fin = open('data_output.txt','w')
for values in fin:
val = values.replace("
","")
data2.append(int(val))
fin.close()
mysum = sum(data2)
fout = open('data_output.txt','a')
fout.write(str(mysum ))
fout.close()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

Explain the goal of behavior therapy.

Answered: 1 week ago

Question

Can consultants replace outsourced activities? Why or why not?

Answered: 1 week ago