Skip to content

Practice module 2

>Operators and Control Flow: coding practice

Start with the lesson drills, then combine the ideas in the module labs. Every task has automatic checks, progressive hints, reset and a solution.

Module coding progress9 exercises available

Lesson coding drills

One focused editor exercise for every lesson in this module. (0/5 passed this visit)

You can run every exercise now. Create a free ID to keep passes, code attempts and XP.

Lesson 1: Python Operators

Not passed yet

Set apples to 23 and boxes to 5. Print how many whole apples go in each box, then print the number left over.

Expected output:

4
3

# Write your code below

Lesson 2: Input, Output and f-strings

Not passed yet

Set name to 'Kai' and score to 12500. Use one f-string to print the sentence below with a thousands separator.

Expected output:

Kai scored 12,500 points.

# Write your code below

Lesson 3: if...elif...else Statements

Not passed yet

Set number to 7. Use an if/else statement to print odd when the number has a remainder of 1 after division by 2; otherwise print even.

Expected output:

odd

# Write your code below

Lesson 4: for Loops and range()

Not passed yet

Use range(1, 6) in a for loop to print the numbers 1 through 5, one per line.

Expected output:

1
2
3
4
5

# Write your code below

Lesson 5: while Loops, break and continue

Not passed yet

Set number to 1 and total to 0. Use a while loop to add the numbers 1 through 4 to total, then print it.

Expected output:

10

# Write your code below

Coding practice: write it yourself

Real Python, real checks: write your answer, press Run checks, and keep going until it passes. (0/4 passed this visit)

You can run every exercise now. Create a free ID to keep passes, code attempts and XP.

Lab 1: Even or odd?

Not passed yet

number = 8. Print EVEN if it divides by 2 with no remainder, otherwise ODD.

number = 8
# your if/else here

Lab 2: Times table rows

Not passed yet

Using a for loop over range(1, 4), print:

5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
for i in range(1, 4):
    # print each row

Lab 3: Pass mark check

Not passed yet

Bangladesh's pass mark is 33. For marks = 38, print PASS when marks is at least 33, else FAIL.

marks = 38
# PASS or FAIL?

Lab 4: Exam countdown

Not passed yet

Print a countdown from 3 down to 1, one number per line, using a while loop.

days = 3
while days > 0:
    # print days, then decrease it

References & Further Reading

Related entries from PyLabs's own reference library.

  • bool() (Convert a value to True or False.)
  • range() (Make a sequence of evenly spaced integers.)
  • enumerate() (Pair each item with a counter.)