Python Basics
Code Logic
Debug This!
Code in Action
Design Thinking
100

What’s the difference between a string and an integer in Python?

Strings are sequences of characters, while integers are whole numbers. You can't do math with strings unless you convert them.

100

What does this print and why? `print("4" * 3)`

`444` — because it's string multiplication, not math.

100

Write code that prints all even numbers from 1 to 20 using a `for` loop.

Use a `for` loop: `for i in range(2, 21, 2): print(i)`


100

What’s the bug? `numbers = [1, 2, 3, 4] for i in range(len(numbers)): print(numbers[i+1])`

Index error — `i+1` goes out of bounds on the last loop.

100

Write a function that returns True if a number is prime.

Loop from 2 to sqrt(n) to check divisibility. Return False if divisible.

200

Name 3 data types in Python and describe how they're used.

Int (whole numbers), str (text), list (ordered group of items).

200

What’s the logic behind this condition? `if not (age >= 13 and age <= 19):`

It's checking if the age is NOT between 13 and 19 — aka not a teenager.

200

Ask the user for their name. If it starts with "A", print "Awesome!" Else, print "Nice to meet you."

name = input("What’s your name? ")

if name[0].upper() == 'A':

    print("Awesome!")

else:

    print("Nice to meet you.")

200

Predict the output: `x = 10 def change(x): x = x + 5 change(x) print(x)`

 It prints 10 — the change to x inside the function doesn’t affect the original.

200

Create a function that returns the highest number in a list (don’t use `max()`).

Loop through the list, keep track of max value manually.

300

What does `len()` do, and when would you use it?

`len()` returns the number of items in a list or the number of characters in a string.

300

When would you use a `while` loop instead of a `for` loop?

`While` loops are better when you don't know how many times you'll loop. `For` loops are for fixed ranges.

300

Code a function that checks if a number is divisible by both 3 and 5.

Use modulo: `if num % 3 == 0 and num % 5 == 0:`

300

Why doesn’t this work right? `for letter in "banana": if letter == "a": count += 1 print(count)`

The `print(count)` is indented inside the loop — it should be outside to only print once.

300

Code a number guessing game (1–10 range, 3 tries max).

Use `random.randint()`, loop 3 times with input and `if` check.

400

What's a syntax error vs. a runtime error?

Syntax error = your code breaks the rules of the language. Runtime error = code runs but crashes while executing.

400

Explain what this function is doing: `def mystery(x): return x[::-1]`

It reverses a string using slicing. `[::-1]` flips the string.

400

Keep asking the user for numbers until they enter `-1`, then print the average (excluding `-1`).

Use a `while` loop, keep a counter and total, break at -1, then compute average.

400

Why might this loop crash? `i = 0 while i < 5: print(i)`

There's no `i += 1`, so it loops forever.

400

Create a password checker (minimum eight characters, must include both numbers and letters).

Use `input()`, check `len()`, use `any()` with `.isalpha()` and `.isdigit()`.

500

Explain the difference between a list and a dictionary.

Lists are ordered and use indexes. Dictionaries use key-value pairs and don't rely on position.

500

Why does this function sometimes give an error? `def divide(a, b): return a / b`

It gives an error if b = 0 — because you can't divide by zero.

500

Write a function that returns the number of vowels in a string.

Loop through string, count characters if they’re in 'aeiou'.

500

Debug this: `def square_all(nums): for n in nums: n = n ** 2 return nums`

You modified `n`, but didn’t update the list. Use indexing or list comprehension.

500

Turn a sentence into “leet speak” (replace letters with numbers like: a→4, e→3, i→1, o→0, etc.)


Use a dictionary to map each target letter to its leet version, then loop through the sentence and build a new string by replacing letters using the dictionary.

def to_leet(sentence):

    leet_map = {'a': '4', 'e': '3', 'i': '1', 'o': '0'}

    result = ''

    for char in sentence:

        result += leet_map.get(char.lower(), char)

    return result

M
e
n
u