Exercise
Calculating The Mean
Objective
Develop a Python program that calculates and displays the average of four numbers provided by the user.
Example Python Exercise
Show Python Code
# Prompt the user to enter the first number
num1 = float(input("Enter the first number: "))
# Prompt the user to enter the second number
num2 = float(input("Enter the second number: "))
# Prompt the user to enter the third number
num3 = float(input("Enter the third number: "))
# Prompt the user to enter the fourth number
num4 = float(input("Enter the fourth number: "))
# Calculate the average of the four numbers
average = (num1 + num2 + num3 + num4) / 4
# Display the result
print(f"The average of {num1}, {num2}, {num3}, and {num4} is {average}")
Output
Enter the first number: 4
Enter the second number: 8
Enter the third number: 6
Enter the fourth number: 10
The average of 4.0, 8.0, 6.0, and 10.0 is 7.0
Share this Python Exercise
Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.
In this exercise, you will develop a Python program to prompt the user for three numbers (a, b, c) and display the result of the expressions (a + b) * c...
In this exercise, you will develop a Python program to prompt the user for their age (e.g., 20) and respond with a message like "You look younger than age...
In this exercise, you will develop a Python program to prompt the user for a number and display it four times in a row, separated by spaces, and then four time...
In this exercise, you will develop a Python program to prompt the user for a number and then display a rectangle 3 columns wide and 5 rows tall using that d...
In this exercise, you will develop a Python program that asks the user for a temperature in Celsius and converts it to both Kelvin and Fahrenheit...
In this exercise, you will develop a Python program to output "Hello" on the screen, followed by your name on a separate line. This exercise is perfect for pra...