Brainlag
  1. Python
  2. Foundations
07/42 lessons

Checkpoint: the basics

Checkpoint25 min4 problems

Learn

On your own now

Four problems that use everything in Foundations: variables, arithmetic, strings, input, conversion and if. No starter code to lean on and no hints until you have checked once. Each problem is checked against several inputs, so a program that only works for the first one will not pass.

If one of them beats you, that is useful information: the result tells you which lesson to go back to.

Checkpoint

Seconds to a track length

Read a number of seconds and print it as minutes and seconds, the way a music app shows a track length: 207 becomes 3:27, 185 becomes 3:05. The seconds always have two digits.

Milestones

  1. 207 seconds
  2. 185 seconds
  3. Under a minute
  4. Exactly ten minutes

On your own: hints appear after your first check, a solution after 3 checks or if you give up.

Your program reads the Input box under the editor. Check also tries 3 other inputs.

exercise_1.py to run

Checkpoint

Check a new username

Read a username. Ignore spaces at either end. Then print the first message that applies:

  • No spaces allowed if there is a space inside it
  • Too short if it has fewer than 3 characters
  • Too long if it has more than 12
  • otherwise OK: followed by the name in lower case

Milestones

  1. Spaces at the ends
  2. Space inside
  3. Two letters
  4. Seventeen letters

On your own: hints appear after your first check, a solution after 3 checks or if you give up.

Your program reads the Input box under the editor. Check also tries 3 other inputs.

exercise_2.py to run

CheckpointPredict the output

Trace the remainder

Type exactly what this prints.

Read the program, type exactly what it prints, then lock it in. It runs after that.

exercise_3.py
x = 7
y = x // 2
x = x % 2
if x == 1 and y > 2:
    print("odd", y)
else:
    print("even", y)
print(f"{x}{y}")

CheckpointFix the bug

Free delivery never applies

Orders of over 50 pounds get free delivery. The program crashes before it prints anything. Fix it.

Milestones

  1. Over 50
  2. Under 50
  3. Exactly 50

On your own: hints appear after your first check, a solution after 3 checks or if you give up.

Your program reads the Input box under the editor. Check also tries 2 other inputs.

exercise_4.py to run
total = input()
if total > 50:
    print("Free delivery")
else:
    print("Delivery: 4.99")
Step 1 of 5
Python 3.13

Code editor. Press Control or Command plus Enter to run the code. Tab indents; to move focus out of the editor, press Escape and then Tab.