Bitpath

Lesson 1 · Unit 02

Conditions

Comparisons, if, elif and else

13 exercisesabout 3 min

What you practise

  • Comparisons, and, or, not, if, elif, else, indentation as structure, = against ==, values that count as true

Try a question from this lesson

Pick one

>= means "greater than or equal to". The program asks a question about age. What does it show?

Python
age = 15
print(age >= 18)

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Comparisons

A comparison gives a bool: True or False.

== asks "are these equal?" and != asks "are these different?". Then there are <, >, <= and >=.

Careful: one = gives a name a value. Two == compare two values.

Python
print(3 < 5)        # True
print(3 == 5)       # False
print(3 != 5)       # True
print("a" == "a")   # True

Concept

if, elif, else

if asks a question. The indented block under it, four spaces in, runs only when the answer is true.

elif ("else if") asks another question, but only when every question before it was false. else takes whatever is left.

Exactly one block runs: the first one whose question is true.

Python
score = 72
if score >= 90:
    print("A")
elif score >= 70:
    print("B")
else:
    print("C")
# shows B

Concept

and, or, not

Join two questions with and or or.

and is true only when both sides are true. or is true when at least one side is. not flips a bool: true becomes false.

Python
age = 20
has_ticket = False
print(age >= 18 and has_ticket)  # False
print(age >= 18 or has_ticket)   # True
print(not has_ticket)            # True

9 more exercises in the app

  • 1× match the pairs
  • 3× multiple choice
  • 2× type the answer
  • 1× fill the blanks
  • 1× true or false
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy