Exam attendance eligibility
Write a Python program that allows a student into the exam only if attendance is at least 75%.
attended 52 of 65 classes, 40 of 65 classes
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")80.0% -> eligible 61.5% -> not eligible
Line by line
Percentage = attended / total × 100.
:.1f prints one decimal place.
Learn the concept
New to this topic? Read the lesson, then come back.