Python Practice › If-Else Programs › Program 54
Exam attendance eligibility
Write a Python program that allows a student into the exam only if attendance is at least 75%.
Input
attended 52 of 65 classes, 40 of 65 classes
Output
80.0% -> eligible 61.5% -> not eligible
Approach
- Calculate the percentage, then compare with 75.
Solution
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.
Learn the concept
New to this topic? Read the lesson, then come back.