Grade Calculator
Take marks (0-100) and print the corresponding grade (A/B/C/D/F).
IntermediatePhase 1 - Level 2: Nested If & Multiple ConditionsExample 3 of 10
grade-calculator.py
1# Take marks as input2marks = float(input("Enter marks (0-100): "))34# Assign grade based on marks5if marks >= 90:6 print("Grade: A")7elif marks >= 80:8 print("Grade: B")9elif marks >= 70:10 print("Grade: C")11elif marks >= 60:12 print("Grade: D")13else:14 print("Grade: F")
Output
Enter marks (0-100): 85 Grade: B Enter marks (0-100): 45 Grade: F
What's going on
Use elif chain to check marks in descending order.
Key Concepts:
Check ranges from highest to lowest
Once a condition matches, rest are skipped
Order matters: check >= 90 before >= 80
🔗Related Content
- 📖
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- 📝
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- 💻
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum