Skip to content
CodeItRaw
Basics

Lesson 2/7

A program sometimes reaches a fork: if the input is like this do one thing, otherwise another. if does that. Next to if you write a question whose answer is either True or False.

def solve(key):
if key > 100:
return "big"
elif key > 10:
return "medium"
else:
return "small"
The questions are asked top to bottom and the first true one runs; the rest are skipped. elif means "otherwise, is this true?" and else means "if none of them".

The tools for asking: == is it equal, != is it different, < > <= >= smaller or larger. % gives the remainder of a division: 7 % 2 is 1, 8 % 2 is 0. That is how you tell whether a number is even.

Tasks

Tasks open in order. Solve them all and the next lesson opens.

This lesson's tasks open when the lessons before it are finished. You can read the explanation now.Go to the current lesson

  1. 01

    Is It Even?

    Function

  2. 02

    Plus or Minus?

    Function

  3. 03

    Leap Year

    Code reading · Break the Code

If you would rather not wait for the order, every problem is open without locks: Problem list