Question: Programming Exercise 3.9 IN PYTHON: Write a program that receives a series of numbers from the user and allows the user to press the enter
Programming Exercise 3.9
IN PYTHON:
Write a program that receives a series of numbers from the user and allows the user to press the enter key to indicate that he or she is finished providing inputs. After the user presses the enter key, the program should print:
The sum of the numbers
The average of the numbers
An example of the program input and output is shown below:
Enter a number or press Enter to quit: 1 Enter a number or press Enter to quit: 2 Enter a number or press Enter to quit: 3 Enter a number or press Enter to quit: The sum is 6.0 The average is 2.0
This is the code that I have so far.
theSum = 0.0 data = input("Enter a number: ") while data != "": number = float(data) theSum += number data = input("Enter the next number: ")
print("The sum is", theSum)
Enter a nunber: 1 Enter the next nunber: 2 Enter the next nunber: 3 Enter the next number: The sun is 6.0 sum.py 1# Edit the code below 3 theSun 0.0 4 datainput( "Enter a nunber:) 5 while data " 6 nunber float (data) 7 theSun number data = input("Enter the next number: ") 9 10 12 print(" The sun is", theSun) 13 14
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
