1.6 Commenting Code -Python with Karel
 
Commenting Your Code with Karel
๐Ÿ‘ฉโ€๐Ÿซ
7th Grade Computer Science โ€“ Python with Karel

Commenting Your Code with Karel

๐Ÿ‘ฉโ€๐Ÿซ Mrs. Jessica Simmons-Fiawoo
โฑ๏ธ 45-50 minutes
๐Ÿ’ป CodeHS.com
1

Why Leave Notes?

๐ŸงฑReal-Life Connection

Imagine you and your friend are building an awesome LEGO tower together. You're halfway through, and the tower is getting really tall and complicated! But suddenly, you have to leave for soccer practice.

๐Ÿ’ญ Think About It: What kind of notes or directions would help your friend finish the tower correctly without you there?

Share Your Ideas:

โฐ Discussion Time: 5 minutes

๐Ÿ’กConnection to Coding:

Programmers do the same thing when they use comments in their code! Comments are like leaving helpful notes in your program so that you (and others) can understand what each part doesโ€”even weeks or months later!

2

Objective & Agenda

๐ŸŽฏToday's Objective:

I can apply comments in Python so others โ€” and I myself โ€” can easily follow and understand my Karel programs.

๐Ÿ’ฌEssential Question:

Why do programmers add comments in their code, and how do comments make programs easier to understand?

๐Ÿ“‹Today's Agenda:

  • Watch & discuss: Commenting Your Code (CodeHS 1.6.1)
  • Practice adding comments (Guided & Partner Practice)
  • Reflect: Why comments matter

๐Ÿ“šMSDE Standard 3B-AP-21

Students should be able to document programs to make them easier to follow, test, and debug.

๐ŸซHCPS CS Standard

Students create programs that include documentation to explain their purpose and function.

๐ŸŽฎWhy This Matters:

Professional game developers use comments all the time! When creating games like Minecraft or Fortnite, hundreds of programmers work on the same code. Comments help them understand what each other's code does without having to guess!

3

Guided Practice

๐Ÿ‘€What Are Comments?

Comments are notes in your code that Python ignores when running the program. They're just for humans to read! In Python, any line starting with # is a comment.

๐Ÿค–Karel's Code Without Comments:

def main(): move() jump_hurdle() move() jump_hurdle() move()

โŒ Can you tell what this code is trying to do? It's hard to know!

โœ๏ธ Your Challenge: Let's add helpful comments to explain what's happening!
๐Ÿ’ก Hint: Start each comment with the # symbol. Good comments explain WHY or WHAT the code does, like "Move to the first hurdle" or "Jump over obstacle."

Add Your Comments:

โœจExample With Good Comments:

# Program to help Karel jump over two hurdles def main(): move() # Move to the first hurdle jump_hurdle() # Jump over the first obstacle move() # Move to the second hurdle jump_hurdle() # Jump over the second obstacle move() # Move to the finish line

โœ… Now it's much easier to understand what Karel is doing!

๐Ÿ“ฑReal-World Connection:

Think about a recipe! When you bake cookies, the recipe doesn't just say "Add ingredients." It explains each step: "Mix butter and sugar until fluffy" or "Bake for 12 minutes." Comments work the same way in codeโ€”they explain each step clearly!

4

Partner Practice

๐Ÿ‘ฅTime to Practice Together!

Now you'll work with a partner on a real CodeHS challenge!

๐Ÿ’ป Activity: Work on CodeHS 1.6.4: The Two Towers + Comments

๐Ÿ“Instructions:

  1. First 5 minutes: Work with your partner to write the Karel program and add helpful comments.
  2. Switch! After 5 minutes, trade computers with another pair of students.
  3. Review: Read the new code and comments. Can you understand what the program does just by reading the comments?
  4. Feedback: Add one improvement suggestion as a comment in their code.

โญWhat Makes a GREAT Comment?

โœ… Good: # Make Karel turn around to face the other direction

โŒ Not Helpful: # Turn left (Too obvious!)

โŒ Not Helpful: # asdfghjkl (Doesn't explain anything!)

๐Ÿ’ก Partner Tips:
  • Take turns typing and explaining your thinking
  • Ask each other: "Why did we use this command here?"
  • Write comments that would help YOU understand the code if you looked at it next month!

๐ŸŽจThink Like a Tour Guide:

Imagine you're giving a tour of your code to someone who's never seen it before. Your comments are like the signs and explanations that help visitors understand what they're looking at. "This section makes Karel climb stairs" is much better than just "Karel moves here"!

5

Hands-On Challenge & Reflection

๐ŸŽฏFinal Challenge: Apply Your Skills!

Now it's time to prove you can apply comments to help others understand your code! Read the uncommented code below, then add helpful comments to make it clear.

๐Ÿค–Mystery Karel Program - Add Comments!

def main(): move() turn_left() move() move() turn_right() move() put_ball()

โ“ What does this program do? Add comments to explain each step!

โœ๏ธYour Turn - Add 5 Comments:

๐ŸŽ“ Did You Apply the Objective? Look back at today's goal: "I can apply comments in Python so others โ€” and I myself โ€” can easily follow and understand my Karel programs." Did your comments help explain what the program does?

๐Ÿ’ญExit Ticket - Reflect on Your Learning

Now that you've applied comments to a real program, answer these reflection questions:

๐ŸŒŸKey Takeaways:

  • Comments start with the # symbol in Python
  • Good comments explain WHAT or WHY, not just repeat the code
  • Comments help YOU remember what you were thinking
  • Comments help OTHERS understand and improve your code
  • Professional programmers use comments every single day!

๐Ÿš€Looking Ahead:

From now on, make it a habit to add comments to ALL your Karel programs! Future you (and your classmates) will thank you. Remember: Code is read way more often than it's written, so make it clear and easy to understand!

๐ŸŽฏChallenge for Next Time:

Go back to an old Karel program you wrote before today. Add comments to it, then show it to a friend. Can they understand what it does now? That's the power of good commenting!

Last updated  2025/10/15 00:46:32 PDTHits  73