Python Programs | IT Developer
IT Developer

Python Programs



Share with a Friend

Python Programs - Input and Output

Input three numbers and display average - Python Program

# Prompt the user to enter the first number and convert it to a float num1 = float(input("Enter the first number: ")) # Prompt the user to enter the second number and convert it to a float num2 = float(input("Enter the second number: ")) # Prompt the user to enter the third number and convert it to a float num3 = float(input("Enter the third number: ")) # Calculate the sum of the three numbers sum_of_numbers = num1 + num2 + num3 # Calculate the average by dividing the sum by 3 average = sum_of_numbers / 3 # Display the calculated average to the user, formatted to two decimal places print(f"The average of {num1}, {num2}, and {num3} is: {average:.2f}")

Output

 
OUTPUT  :
Enter the first number: 12
Enter the second number: 42
Enter the third number: 32
The average of 12.0, 42.0, and 32.0 is: 28.67