← Back to CS50P Problem Sets Home CS50P Problem Set 2 Student Support

CS50P – Problem Set 2 Help Page

This page helps you practice each Problem Set 2 skill step by step. If you get stuck, ask: “Which Week 2 idea does this problem want me to use?”

How to Use This Page

  1. Click a problem tab.
  2. Read the task and steps.
  3. Click Load worked example to see a complete similar program.
  4. Click Load starter code to begin your own version.
  5. Press Run Code (or Ctrl+Enter) to test.

Usage Guidelines (Do / Don't)

🚫 Do NOT:
  • Copy code from this page directly into your CS50 submission
  • Skip reading the official CS50 problem description
✅ DO:
  • Use this page to understand patterns and approaches
  • Write your own version in your CS50 codespace

Pick a Problem

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.
1. Read goal 2. Start Here 3. Load starter 4. Run once 5. Fix + retest

Problem 1 – camel.py

Skill: Loop through letters
⏱️ Expected: 20–25 min ⚡ Challenge: Easy–Medium

💡 This is how code formatters and APIs convert variable styles — used in every major codebase.

Convert a camelCase word typed by the user into snake_case.

Lecture pattern
for c in text:
    print(c)

c.isupper()

Example from the notes

students = ["Hermione", "Harry", "Ron"]

for student in students:
    print(student)
  1. Ask the user to type text.
  2. Check one character at a time.
  3. If the character is uppercase, add _ and the lowercase letter.
  4. If not uppercase, add the character as-is.
👉 Start Here
  1. Create your file: camel.py
  2. Add text = input("camelCase: ")
  3. Set result = ""
  4. Write a for c in text: loop
  5. Print the result (even if wrong at first)
Input:helloWorld
Output:hello_world
Input:camelCase
Output:camel_case
  • 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
Official CS50 camel.py spec

Quick Reference (At a Glance)

Quick reference table showing each CS50P problem and its main Week 2 concept.
Problem Concept from Lecture
camel.py Loop through characters
coke.py While loops
twttr.py Filtering characters
plates.py String validation
nutrition.py Dictionaries

Try Code Here

Loading Python…
Loaded code info: none yet.

Use Ctrl+Enter to run. If your code has input(), a pop-up will ask for your answer.

Instructional Workflow Checklist

Editor mode: basic editor (trying to load color highlighting…)
Output

                    

Error Decoder

If your code fails, match the error type to the next step:

  • IndentationError → Check spacing inside your if, for, and while blocks.
  • NameError → Check spelling and capitalization of variable/function names.
  • SyntaxError → Look for missing :, quotes, or parentheses on the reported line.
  • ValueError → Validate input before converting (for example, check .isdigit() first).
  • TypeError → Confirm you are combining compatible types (string vs number).
Tip: Start with the first line in the traceback that points to your code.

Debugging Checklist

Most bugs happen when code does something different than you expected. Check one line at a time.