Question

Write a Python program which calculates the average of the numbers entered by the user through...

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

Homework Answers

Answer #1
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))

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python code Write a complete program with for loop which calculates the sum of the numbers...
Python code Write a complete program with for loop which calculates the sum of the numbers from 1 to 100
Write a python program that calculates the area of triangle. The user will be asked to...
Write a python program that calculates the area of triangle. The user will be asked to enter the base (b) and the height (h). The formula to calculate the area is: Triangle_area=(bh)/2 Note: the program should print the area to the user: (for example: the area of the triangle is: 34.3)
IN PYTHON : Write a program that asks the user for a number. Write the number...
IN PYTHON : Write a program that asks the user for a number. Write the number to a file called total.txt. Then ask the user for a second number. Write the new number on line 2 with the total for both numbers next to it separated by a comma. Then ask the user for a third number and do the same. Keep asking for numbers until the person puts in a zero to terminate the program. Close the file. Be...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
Write a python program that does the following: Prompts the user for three numbers in one...
Write a python program that does the following: Prompts the user for three numbers in one request. Be sure to specify the “delimiter” by which a user enters those three numbers. Divides the first number by the second number and add that result to the third number. Prints output that shows in one line the formula applied and the result of the calculation. Validate input by: •    Checking the user entered 3 values •    Appropriately checking for the following errors:...
- Write a Python program which asks the user to enter a number, if the number...
- Write a Python program which asks the user to enter a number, if the number is divisible by 6 or 7, the program prints “The number X is divisible by 6 or 7” and if the number is neither divisible by 6 nor by 7, then it prints “The number X is not divisible by 6 and 7”.
Write a Python program that plays a number guessing game with a human user. The human...
Write a Python program that plays a number guessing game with a human user. The human user will think of a number between 1 and 100, inclusive. Then the program has to guess what the user entered. keep track of the number of interaction it takes for the computer to guess the number. sample run: enter number to be guessed:88 output: you entered 88, and it took the program 3 iterations to guess.
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...
Question1: Write a Python Program that asks for the grades of 5 quizzes and then prints...
Question1: Write a Python Program that asks for the grades of 5 quizzes and then prints the highest grade. [6 Marks] Question2: Write a Python Program that does the following tasks. [8 Marks] Create an empty list Ask the user for 5 positive numbers and append them to the list Find and print the sum of all the numbers in the list Delete the last element from the list and then print the list Question3: Consider you have the following...
Use C++ Write a program that first reads in how many whole numbers the user wants...
Use C++ Write a program that first reads in how many whole numbers the user wants to sum, then reads in that many whole numbers, and finally outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the numbers just once each and the user can enter them...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT