Python Control Flow
💡
Exercise 12

Grades 10 XP Easy

Ctrl+Enter Run Ctrl+S Save

When you need to check multiple conditions, use elif (short for "else if"):

score = 85 if score >= 90: print('A') elif score >= 80: print('B') elif score >= 70: print('C') elif score >= 60: print('D') else: print('F')

Python checks each condition from top to bottom. The first one that's True gets executed, and the rest are skipped.

Relational operators compare two values:

  • `==` equal to
  • `!=` not equal to
  • `>` greater than
  • `<` less than
  • `>=` greater than or equal
  • `<=` less than or equal
📋 Instructions
Create a variable `grade` and set it to `92`. Write an `if`/`elif`/`else` chain that prints: - `'A'` if grade >= 90 - `'B'` if grade >= 80 - `'C'` if grade >= 70 - `'D'` if grade >= 60 - `'F'` otherwise Expected output: `A`
Use if/elif/else: if score >= 90: grade = 'A', elif score >= 80: grade = 'B', and so on down to 'F'. Check from highest to lowest!
⚠️ Try solving it yourself first — you'll learn more!
score = 85

if score >= 90:
    print('A')
elif score >= 80:
    print('B')
elif score >= 70:
    print('C')
elif score >= 60:
    print('D')
else:
    print('F')
main.py
Hi! I'm Rex 👋
Output
Ready. Press ▶ Run or Ctrl+Enter.