to input 10 numbers and print their sum and average using while loop to make a Python program
Answers
Explanation:
The following steps are taken to make the program-
- Declare the required variables.
- use the while loop.
- inside the loop, input the values and calculate the sum.
- outside the loop, calculate the average.
- finally, print the answer.
Program:
print("Enter 10 numbers")
i = 0 # to iterate the loop
s = 0 # intializing the value to 0 to calculate the sum
while i < 10:
n = int(input()) # taking input as integer
s = s + n # modifying the variable to calculate the sum after every input
i += 1 # incrementing the loop counter
avg = s / 10 # calculating the average of the values
print("The sum is = ",s)
print("The average is =",avg)
#answerwithquality
#BAL
Explanation:
The following steps are taken to make the program-
Declare the required variables.
use the while loop.
inside the loop, input the values and calculate the sum.
outside the loop, calculate the average.
finally, print the answer.
Program:
print("Enter 10 numbers")
i = 0 # to iterate the loop
s = 0 # intializing the value to 0 to calculate the sum
while i < 10:
n = int(input()) # taking input as integer
s = s + n # modifying the variable to calculate the sum after every input
i += 1 # incrementing the loop counter
avg = s / 10 # calculating the average of the values
print("The sum is = ",s)
print("The average is =",avg)
#answerwithquality
#BAL