Ask Question
10 May, 23:24

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

BASE CODE

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)

+3
Answers (1)
  1. 11 May, 03:20
    0
    theSum = 0.0#defined in the question.

    count=0 #modified code and it is used to intialize the value to count.

    data = input ("Enter a number: ") #defined in the question.

    while data! = "": #defined in the question.

    number = float (data) #defined in the question.

    theSum + = number #defined in the question.

    data = input ("Enter the next number or press enter to quit ") #defined in the question "only some part is modified"

    count=count+1#modified code and it is used to count the input to print the average.

    print ("The sum is", theSum) #defined in the question.

    print ("The average is", theSum/count) #modified code and it is used to print the average value.

    output:

    If the user inputs as 1,4 then the sum is 5 and the average is 2.5.

    Explanation:

    The above code is written in the python language, in which some part of the code is taken from the question and some are added. The question has a code that tells the sum, but that code is not print the average value of the user input value. To find the average, some codes are added, in which one count variable which is initialized at the starting of the program and gets increased by 1, when the user gives the value. Then that count divides the sum to print the average.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “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 ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers