Bitpath

Boss lesson · Unit 03

A text toolkit

Small functions, tested and combined

13 exercisesabout 3 min

What you practise

  • Small functions built and combined: a palindrome check, a vowel counter, a Caesar shift, each one checked with assert against answers you know

Try a question from this lesson

Pick one

You will build three tools for working with words. First, a new trick: for can walk through a string. What does this show?

Python
for ch in "cat":
    print(ch)

The ideas

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

Concept

assert

How do you know a function works? Check it against answers you already know.

assert takes a claim. If the claim is true, nothing happens. If it is false, the program stops with an AssertionError.

A few asserts under a function are a test that runs every time the program does.

Python
def double(n):
    return n * 2

assert double(4) == 8    # true: silent
assert double(0) == 0
print("all tests passed")

Concept

in

in asks whether one string appears inside another. The answer is a bool, so it fits straight into an if.

With a single character on the left, it asks "is this character one of these?".

Python
print("a" in "aeiou")     # True
print("b" in "aeiou")     # False
print("ell" in "hello")   # True

10 more exercises in the app

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

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