Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Writing and reading files is an important aspect of many programs. Suppose you have to create a program that writes the number 0 to a

Writing and reading files is an important aspect of many programs. Suppose you have to create a program that writes the number 0 to a file c_output.txt, then later reads this file, and then adds the number back to the file.
Which code applies write and read methods appropriately to perform this task?
a.)
data_w =[0]
fout = open('c_output.txt','r')
for val in data_w:
fout.write(val+'
')
fout.close()
data_r =[]
fin = open('c_output.txt','w')
for values in fin:
val = values
data_r.append(int(val))
fin.close()
b.)
data_w =[0]
fout = open('c_output.txt','w')
for val in data_w:
fout.write(str(val)+'
')
fout.close()
data_r =[]
fin = open('c_output.txt','w')
for values in fin:
val = values
data_r.append(val)
fin.close()
c.)
data_w =[0]
fout = open('c_output.txt','r')
for val in data_w:
fout.write(str(val)+'
')
fout.close()
data_r =[]
fin = open('c_output.txt','w')
for values in fin:
val = values
data_r.append(int(val))
fin.close()
d.)
data_w =[0]
fout = open('c_output.txt','w')
for val in data_w:
fout.write(str(val)+'
')
fout.close()
data_r =[]
fin = open('c_output.txt','r')
for values in fin:
val = values
data_r.append(int(val))
fin.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 Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions