Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is the txt file given. Working with Python in Jupyter, on PC. Thank you. Exercise 1 Write code that reads the file line-by-line numbers.txt,
This is the txt file given. Working with Python in Jupyter, on PC. Thank you.
Exercise 1 Write code that reads the file line-by-line numbers.txt, then does the following: Sum all the numbers in numbers.txt, then prints the numbers to the screen. Next, append the string "SUM: K", where k is the calculated sum, to the end of numbers.txt as a new line. Finally, print the entire file to make sure you appended to the file correctly. The absolute path for the file is "..umbers.txt" Important Python concepts: for, open ('a' and 'r'), write().print() In [ ]: # If you mess up the file and need to try again, run this cell with open('numbers.txt', 'w') as in_file: in_file.write('42 18 22 18') with open("numbers.txt") as iFile: print(iFile.read() In [ ]: # Write code to read file and calculate sum here In [ ]: # Print sum here In [ ]: # Write code to append to file here Run the line below to check your work In [ ]: with open("numbers.txt") as iFile: print(iFile.read() numbers.txt - Notepad File Edit Format View Help 142 18 22 18 SUM: 100.0Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started