script_2.py - Grade Evaluator
Code
#!/usr/bin/env python3
"""Grade evaluator"""
score = float(input("Enter your test score: "))
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
elif score >= 70:
print("Grade: C")
elif score >= 60:
print("Grade: D")
else:
print("Grade: F")
Explanation
Line 4: score = float(input("Enter your test score: "))
- input() returns a string type (str)
- float() converts string to floating-point decimal number
- float type allows decimal values like 85.5
- score variable stores the float value
Line 6: if score >= 90:
- First condition checked in the chain
- If True, executes line 7 and skips all elif/else blocks
Line 8: elif score >= 80:
- elif means "else if" - only checked if previous conditions are False
- Checks if score is between 80 and 89.99
- Multiple elif allows checking ranges in order
Line 10-13: Additional elif blocks
- Each elif is only evaluated if all previous conditions were False
- Creates cascading range checks: 70-79 for C, 60-69 for D
Line 14: else:
- Catches all remaining cases (score < 60)
- Only executes if none of the if/elif conditions were True