Question: I have a progam already I need help with the modifying bullet points! I do not know how to do the .txt things! PLEASE HELP!!

Write a program which repeatedly reads numbers until the user enters "done". Once "done" is entered, print out the total, count, and average of the numbers. If the user enters anything other than a number, detect their mistake using try and except and print an error message and skip to the next number. Sample output: Enter a number: 4 Enter a number: 5 Enter a number: bad data Invalid input Enter a number: 7 Enter a number: done 1635.333333333333333 - Modify the program such that it directs the screen output to a file called test.txt. - Modify the program such that it prints the output into a file called outfile.txt using formatting of the data. - Modify the program such that it prints the output into a file called outfile.txt converting the data into strings. - What happens if you do not convert the data into strings in the previous exercise? \( \begin{array}{ll}1 & \text { sum }=0 \\ 2 & \text { count }=0 \\ 3 & \text { average }=0 \\ 4 & \\ 5 & \text { While True: } \\ 6 & \text { try: } \\ 7 & x=\text { input("Enter a number:" ") } \\ 8 & \text { if }(x==\text { "done") : } \\ 9 & \text { break } \\ 10 & \text { value }=\text { float }(x) \\ 11 & \text { sum }=\text { value }+\text { sum } \\ 12 & \text { count }=\text { count }+1 \\ 13 & \text { average = sum } / \text { count } \\ 14 & \text { except: } \\ 15 & \text { print("Invalid input, ") } \\ 16 & \text { my_short_number }=\text { 's.2f'saverage } \\ 17 & \text { print (sum, count, my_short_number) } \\ 18 & \end{array} \)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
