Respuesta :
Answer:
The solution code is written in Python 3
- count = 0
- sum = 0
- num = input("Enter a number: ")
- while(num != ''):
- sum += float(num)
- count += 1
- num = input("Enter a number: ")
- print("Sum : " + str(sum))
- print("Average: " + str(sum / count))
Explanation:
Firstly, we declare two variables count and sum to hold the number of input number and the total of the input number, respectively (Line 1-2)
Next, we prompt user to input the first number (Line 4). While the num is not ' ' (This means it is not "Enter" key), accumulate the num to sum variable and increment count by one (Line 6-8) and then prompt the user to input the next number (Line 9).
At the end, display the sum and average using print function (Line 11 -12).
Following are the python code to the given question:
Program Explanation:
- Defining "s, n" variable that initializes the value, and defines while loop.
- Inside the loop "d" variable is declared that inputs the value by user-end.
- Inside this, if block, is defined the check value is empty so, it breaks the condition, and in the "s" variable it adds the input value.
- After adding value, "n" is defined that incrementing its value, and use print method is used that prints sum and calculates the average value.
Program:
s = 0.0#defining a double variable that initializes a value 0
n = 0 #defining an integer variable that initializes a value 0
while True:#defining a while loop that adds inputs value
d= input("Enter a number or press Enter to quit: ")#defining d variable that inputs value
if d == '':#defining if block that checks d value equal to empty or space value
break#using break condition
s = s+float(d)#using s variable that adds value
n =n+ 1#defining n variable that incrementing its value
print("The sum is", s)#using print method that prints addition of the value
print('The average is', s / n)#using print method that calculate the average of the value
Output:
Please find the attached file.
Learn more:
brainly.com/question/13434486
