Skip to content
Exercises · Q17

Q.Write a program to find average of three numbers.

West Bengal WbchseTextbookSubjective· 3mImportance★★★★★est
90% · 44/49 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Sum the three inputs and divide by 3 — average = (a + b + c) / 3 — remembering the parentheses; inputs 10, 20, 30 give 20.0.

The concept is again operator precedence in a formula: division binds tighter than addition, so the sum must be parenthesised before dividing by 3.

# Average of three numbers
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))

average = (a + b + c) / 3
print("Average =", average)

Key lines:

  • float() lets the program average decimal values (e.g. marks like 78.5) — int() would reject them.
  • (a + b + c) / 3 — with the parentheses the sum is computed first; / then returns a float, so the average is exact even when the sum isn't divisible by 3.

Sample run:

Enter first number: 10
Enter second number: 20
Enter third number: 30
Average = 20.0
``` …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.