Write a Python program which calculates the average of the numbers entered by the user through the keyboard. Use an interactive loop and ask the user at each iteration if he/she wants to enter more numbers. At the end dispay the average on the screen. Using built-in library functions for finding average is not allowed.
Sample output of the program:
Enter a number > 23
More numbers (yes or no)? y
Enter a number > 4
Do you have more numbers (yes or no)? yes
Enter a number > 42
Do you have more numbers (yes or no)? yess
Enter a number > 22
Do you have more numbers (yes or no)? y
Enter a number > 33
Do you have more numbers (yes or no)? no
Average = 24.80
total, count = 0, 0 n = float(input("Enter a number > ")) total += n count += 1 choice = input("More numbers (yes or no)? ") while choice.lower() in ['y', 'yes', 'yess']: n = float(input("Enter a number > ")) total += n count += 1 choice = input("Do you have more numbers (yes or no)? ") print("Average = {:.2f}".format(total / count))
Get Answers For Free
Most questions answered within 1 hours.