Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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!!

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!!
image text in transcribed
image text in transcribed
this us all i have so far!
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

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

More Books

Students also viewed these Databases questions

Question

Draw a labelled diagram of the Dicot stem.

Answered: 1 week ago