If-Else Statement in Python

Level 251 keystrokes

This checks if x is greater than 10. Since 15 > 10 is true, it prints 'big'. Otherwise, it would print 'small'.

Python code

# Assign the value 15 to variable x
1x = 15
# if checks a condition - code below runs only when true
# x > 10 compares if 15 is greater than 10 (it is)
2if x > 10:
# This runs because 15 > 10 is True
3 print("big")
# else provides alternative code when the condition is false
4else:
# This would run if x was 10 or less
5 print("small")

Output

big
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Python code and how often they appear.

  • "× 4
  • :× 2
  • (× 2
  • )× 2
  • =× 1
  • >× 1

More Python examples at level 2

← Python typing practice