Each tab shows a quick plan and lecture pattern. Use it to guide your work without
giving away your final CS50 answer.
Now: Read the task for
camel.py, then load starter code and run once.
⏱️ Expected: 20–25 min
⚡ Challenge: Easy–Medium
💡 This is how code formatters and APIs convert variable styles — used in
every major codebase.
🟦 What You Are Building
Convert a camelCase word typed by the user into snake_case.
🟨 What You Need to Know
Lecture pattern
for c in text:
print(c)
c.isupper()
Example from the notes
students = ["Hermione", "Harry", "Ron"]
for student in students:
print(student)
🟩 Step-by-Step Thinking
- Ask the user to type text.
- Check one character at a time.
- If the character is uppercase, add
_ and the lowercase letter.
- If not uppercase, add the character as-is.
👉 Start Here
- Create your file:
camel.py
- Add
text = input("camelCase: ")
- Set
result = ""
- Write a
for c in text: loop
- Print the result (even if wrong at first)
📥 Example Input / Output
Input:helloWorld
Output:hello_world
Input:camelCase
Output:camel_case
🟥 Common Mistakes
- Adding
_ but forgetting to lowercase the letter after it
- Printing one character at a time instead of building a
result string
- Using
print() inside the loop instead of appending to result
🔁 If You're Stuck
- Can't start? → Load starter code below
- Wrong output? → Add
print(c) inside your loop to see
each character
- Error message? → Check the colon after
for c in text:
and your indentation
⬜ Try It Yourself
⏱️ Expected: 25–35 min
⚡ Challenge: Medium
💡 Vending machine logic is how real payment systems validate
transactions and track running balances.
🟦 What You Are Building
A coin machine that starts at 50 cents and only accepts coins of 25,
10, and 5.
🟨 What You Need to Know
Lecture pattern
while amount_due > 0:
...
Example from the notes
i = 0
while i < 3:
print("meow")
i += 1
🟩 Step-by-Step Thinking
- Start with
amount_due = 50.
- Keep asking for coins while money is still due.
- Only subtract valid coins (25, 10, or 5); ignore anything else.
- When done, print the change owed.
👉 Start Here
- Create your file:
coke.py
- Set
amount_due = 50
- Write a
while amount_due > 0: loop
- Print
"Amount Due:" inside the loop
- Add input and test it — then add the valid-coin check
📥 Example Input / Output
Insert:25 → Amount Due: 25
Insert:25 → Change Owed: 0
Insert:30 →
(ignored, not a valid coin)
Insert:10 → Amount Due: 40
🟥 Common Mistakes
- Not checking
.isdigit() before converting to int — causes a crash on bad
input
- Accepting any coin value, not just 25, 10, and 5
- Printing "Amount Due" after the loop ends instead of inside it
🔁 If You're Stuck
- Can't start? → Load starter code below
- Infinite loop? → Make sure you subtract from
amount_due inside the loop
- Crashes on bad input? → Add
if coin_text.isdigit():
before converting
⬜ Try It Yourself
⏱️ Expected: 15–20 min
⚡ Challenge: Easy
💡 Text filtering like this is used in content moderation tools, social
media apps, and chat pipelines.
🟦 What You Are Building
Remove all vowels (a, e, i, o, u — upper and lower) from text the user
types.
🟨 What You Need to Know
Lecture pattern
for c in text:
...
Key tools:
"aeiouAEIOU" — a string of all vowels to check against
if c not in vowels: — keep non-vowels only
Example from the notes
for _ in range(3):
print("meow")
🟩 Step-by-Step Thinking
- Ask the user for text.
- Loop through each character.
- Keep only characters that are NOT vowels.
- Include both lowercase (
aeiou) and uppercase (AEIOU).
👉 Start Here
- Create your file:
twttr.py
- Add
text = input("Input: ")
- Set
output = ""
- Write a
for c in text: loop
- Print
output (fix vowels after it works)
📥 Example Input / Output
Input:Hello
Output:Hll
Input:Twitter
Output:Twttr
🟥 Common Mistakes
- Only listing lowercase
"aeiou" and missing uppercase vowels like
A, E
- Printing each character inside the loop instead of building a result string
- Using the wrong output label — check the exact format in the CS50 spec
🔁 If You're Stuck
- Can't start? → Load starter code below
- Vowels still appearing? → Check your vowels string includes
AEIOU
- Error message? → Check indentation and colon after your
for line
⬜ Try It Yourself
⏱️ Expected: 35–50 min
⚡ Challenge: Hard
💡 This is validation logic — the same pattern used in web forms, app
sign-ups, and ID verification systems.
🟦 What You Are Building
Check if a license plate string follows every rule:
- Starts with two letters
- Length is 2 to 6 characters
- Numbers appear only at the end
- First number cannot be 0
- No punctuation or spaces
🟨 What You Need to Know
Lecture pattern
s.isalpha()
s.isdigit()
Also available – re module
import re
re.fullmatch(r"[A-Za-z0-9]+", s)
Example from the notes
students = {
"Hermione": "Gryffindor",
"Harry": "Gryffindor",
}
for student in students:
print(student, students[student], sep=", ")
🟩 Step-by-Step Thinking
- Write a function
is_valid(s) that returns True or
False.
- Check length first (must be 2–6).
- Check that the first two characters are letters.
- Check that numbers only appear at the end (no letter after a digit).
- Check that the first digit is not
0.
- Check that only letters and digits appear (no spaces or punctuation).
👉 Start Here
- Create your file:
plates.py
- Write
def is_valid(s): and return False for now
- Test mentally:
"AA10" should be Valid
- Add one rule at a time and test after each
- Add the
input() call last
📥 Example Input / Output
Input:AA10 → Valid
Input:AA01 → Invalid (first digit is
0)
Input:AB →
Valid (letters only, length 2)
Input:1A → Invalid (must start with
2 letters)
🟥 Common Mistakes
- Checking rules in the wrong order — check length first
- Forgetting that a letter after a digit makes the plate invalid
- Not returning
True at the end after all checks pass
- Missing that "first digit can't be 0" is a separate rule from "no punctuation"
🔁 If You're Stuck
- Can't start? → Load starter code below
- Always returns Invalid? → Make sure you
return True at
the end of the function
- Confused about number rules? → Re-read the official CS50 spec
carefully
- Error message? → Check your function is defined before you
call it
⬜ Try It Yourself
⏱️ Expected: 20–30 min
⚡ Challenge: Easy–Medium
💡 Dictionary lookups are how databases and APIs retrieve information by
key — used in every app that stores data.
🟦 What You Are Building
Look up a fruit the user types and print its calorie count using a
dictionary.
🟨 What You Need to Know
Lecture pattern
fruits = {
"apple": 130,
"banana": 110
}
if fruit in fruits:
...
Key tools:
.strip() → removes extra spaces
.lower() → makes comparison case-insensitive
if key in dict: → safe lookup before accessing
Example from the notes
students = {
"Hermione": "Gryffindor",
"Harry": "Gryffindor",
"Ron": "Gryffindor",
}
print(students["Hermione"])
🟩 Step-by-Step Thinking
- Create a dictionary of fruits and their calorie counts.
- Ask for a fruit using
input("Item: ").
- Use
.strip().lower() to normalize the input.
- If the fruit exists in the dictionary, print its calories.
👉 Start Here
- Create your file:
nutrition.py
- Add the fruit dictionary from the official CS50 spec
- Add
fruit = input("Item: ").strip().lower()
- Add an
if check and print the calories
📥 Example Input / Output
Input:Apple
Output:Calories: 130
Input:Watermelon
Output:Calories: 80
🟥 Common Mistakes
- Not using
.lower() — "Apple" and "apple" are
different keys
- Printing something when the fruit is not found (check the spec — it expects silence)
- Not including the full fruit list from the official CS50 problem
🔁 If You're Stuck
- Can't start? → Load starter code below
- Nothing prints? → Add
.lower() to your input and check
spelling
- Key error? → Use
if fruit in fruits: before accessing
the dictionary
⬜ Try It Yourself