Question: Open the file oddsw.txt using a with context. The file should contain the odd numbers you created on a previous assignment. Read the numbers

Open the file "oddsw.txt" using a with context. The file should contain the odd numbers you created on a previous assignment.
Read the numbers in, and display the sum of the numbers on the file. Add to my code to call "int" to change string to number in a for a con: from BrowserFile import open
with open("oddsw.txt","w") as f:
for n in range(1,100,2):
f.write(str(n)+"
")
with open("oddsw.txt","r") as f:
total_sum = sum(int(line.strip()) for line in f)
print(total_sum)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!