Exam attendance eligibility

EasyIf-Else Programs · 54 of 64

Write a Python program that allows a student into the exam only if attendance is at least 75%.

Advertisement
Input
attended 52 of 65 classes, 40 of 65 classes
Output
80.0% -> eligible
61.5% -> not eligible

Approach

  1. Calculate the percentage, then compare with 75.

Solution

Python
for attended in [52, 40]:    total = 65    percent = attended / total * 100    if percent >= 75:        print(f"{percent:.1f}% -> eligible")    else:        print(f"{percent:.1f}% -> not eligible")
Output
80.0% -> eligible
61.5% -> not eligible

Line by line

Line 3

Percentage = attended / total × 100.

Line 5

:.1f prints one decimal place.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More if-else programs

← All 64 If-Else Programs