Question 17 of 22beginner🔧 ApplyLong Answer4 marks

Write a program to find average of three numbers.

Correct Answer

Program to find average of three numbers

num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) num3 = float(input("Enter third number: "))

average = (num1 + num2 + num3) / 3

print("The average of three numbers is:", average)

Output: Enter first number: 10 Enter second number: 20 Enter third number: 30 The average of three numbers is: 20.0

Exercise: EXERCISE | Q: 17 | (Page 32)
For More Understanding

Explanation

The textbook demonstrates the formula for calculating average in the Identifiers section: avg = (marks1 + marks2 + marks3) / 3. This program uses three variables (num1, num2, num3) to store the input values. The float() function is used for explicit type conversion to handle decimal numbers, as shown in Program 5-5 of the context. The average is calculated by adding all three numbers and dividing by 3. The result is then displayed using the print statement.

Solution Steps

  1. Step 1: Accept three numbers as input from the user using input() function and convert them to float type.

  2. Step 2: Calculate the average using the formula: average = (num1 + num2 + num3) / 3

  3. Step 3: Display the result using print() statement.