1.3 KAREL CAN'T TURN RIGHT -CodeHS.com lesson
 
Python Functions ๐Ÿ | 1.3 Karel Can't Turn Right
๐Ÿ
Python CodeHS 1.3 Nearpod Lesson

Python Functions
Your Code Superpowers
Unlocked!

Today YOU become a Python Software Engineer. Build real functions, solve Karel problems, and write code like the pros at Google and Netflix.

๐ŸŽฏ What Are Functions?

Think of a Function as Your Personal Robot Assistant

You teach it how to do a specific task once, and then you can ask it to do that task whenever you want โ€” just by saying its name!

Python
1def turn_right():
2 turn_left()
3 turn_left()
4 turn_left()
5
6# Now you can use it!
7turn_right() # Karel turns right!
๐Ÿ“ Python Function Writing Format โ€” Line by Line:
  • Line 1: Start with the def keyword
  • Line 1: Add your function name using lowercase_with_underscores
  • Line 1: Add parentheses () after the name
  • Line 1: End with a colon : โ€” never forget this!
  • Lines 2+: Indent 4 spaces (or 1 tab) for every command in the body
  • Body: Write all commands that should run when you call the function
๐Ÿ• Real-World Example

Making Pizza

Would you really type all these steps every single time someone orders pizza? What if there are 1,000 orders?

โŒ Without Functions

Every time you want pizza, you repeat:

  • Roll dough
  • Add sauce
  • Add cheese
  • Add toppings
  • Bake for 15 minutes
  • ...repeated 1,000ร— ๐Ÿ˜ญ
โ†’
โœ… With a Function

Create make_pizza() once, then call it!

Python
1def make_pizza():
2 roll_dough()
3 add_sauce()
4 add_cheese()
5 bake(15)
6
7# 1,000 orders = 1,000 calls:
8make_pizza() โœ“
๐Ÿ› ๏ธ Function Anatomy

Dissecting a Python Function โ€” Line by Line

Every part has a job. Learn each one and you'll never write a broken function again.

Python
1def function_name(): โ† Function definition
2 # Function body โ† These are the steps
3 command1()
4 command2()
5 command3()
6
7function_name() โ† Calling the function
๐Ÿ”‘

def

Stands for "define." Tells Python you are creating a new function.

๐Ÿ“›

snake_case Name

Lowercase with underscores. Describes exactly what the function does.

๐Ÿ”ต

Colon (:)

Required at the end of line 1. If you forget it, Python throws an error!

โžก๏ธ

Indentation

4 spaces or 1 tab. Python requires this to know what's inside the function.

๐Ÿ“ฑ Real-World: Your Morning Routine

One Call. Five Tasks Done.

Instead of doing 5 things every morning manually, you just call ONE function!

Python
1def get_ready_for_school():
2 wake_up()
3 brush_teeth()
4 get_dressed()
5 eat_breakfast()
6 pack_backpack()
7
8# Every morning you just run:
9get_ready_for_school()
โšก Power of Functions: Instead of calling 5 separate commands every morning, you just call get_ready_for_school() once โ€” and all 5 steps run automatically!
โš™๏ธ Guided Practice โ€” 5-Step Engineering Process

Solving the Karel Problem

Real engineers follow a process. You will too โ€” right now!

1

Identify the Problem

Karel can't turn right. We need this capability to solve more complex mazes and towers!

2

Design a Solution

How can we simulate a right turn using only turn_left()? Think about a compass โ€” 3 left turns = 1 right turn!

3

Implement โ€” Write the Smart Shortcut

Python
1def turn_right():
2 turn_left()
3 turn_left()
4 turn_left()
4

Test the Solution ๐Ÿƒ

Stand up! Turn left three times together. Did you end up facing the same direction as one right turn? Yes โ€” it works! Our engineering solution is verified.

5

Use It Efficiently

Apply turn_right() in CodeHS 1.3.3: Tower and Turn Right. One call replaces three turn_left() commands every time!

๐Ÿ’ช Why Functions Are Awesome

4 Superpowers Every Engineer Uses

This is why professional engineers at Google, Netflix, and your favorite game studios love functions!

๐Ÿ”„

No More Repetition

Write once, use everywhere! This is the DRY Principle โ€” Don't Repeat Yourself.

๐Ÿงน

Cleaner Code

Your code looks organized and professional โ€” like a tidy room vs. a messy one!

๐Ÿ›

Easier Debugging

If something breaks, you only fix it in one place โ€” not 100 times!

๐Ÿค

Better Teamwork

Other programmers can easily understand and use your functions without knowing how they work inside.

๐ŸŒŸ Cool Real-World Function Examples

Functions Power Everything You Use

Every time you respawn, post a photo, start a movie, or ride in a self-driving car โ€” a function is running.

๐ŸŽฎ Gaming

Python
1def respawn_player():
2 restore_health(100)
3 move_to_checkpoint()
4 reset_inventory()
5 play_respawn_sound()

When called: all 4 commands run automatically!

๐Ÿ  Smart Home

Python
1def movie_night():
2 dim_lights()
3 turn_on_tv()
4 set_volume(15)
5 close_curtains()
6 order_popcorn()

One command sets up your whole movie experience!

๐Ÿš— Self-Driving Car

Python
1def park_car():
2 check_spot()
3 signal_turn()
4 slow_down()
5 turn_wheel()
6 reverse_slowly()
7 stop()

Complex parking broken into simple steps!

๐ŸŽช Interactive Function Demo

Watch a Function Execute Live!

Click the button to see make_sandwich() run step by step.

Python
1def make_sandwich():
2 get_bread()
3 add_peanut_butter()
4 add_jelly()
5 put_top_slice()
6 cut_diagonally()
7
8make_sandwich() โ† Click Run!
Output will appear here when you click Run...
๐Ÿ’ป CodeHS Activities

Apply Your Superpowers!

Open CodeHS and complete both challenges using your new turn_right() function.

๐Ÿ—ผ

Activity 4 โ€” 1.3.3: Tower and Turn Right Individual

Apply turn_right() to build a tower and navigate Karel. Check: correct def, colon, and indentation!

Open CodeHS โ†’
๐Ÿš’

Activity 5 โ€” 1.3.4: Fireman Karel Collaboration

Work with a partner! Solve Fireman Karel using custom functions. Look for repeated patterns โ€” can you turn ANY of them into a function?

Open CodeHS โ†’
๐Ÿ‘€ Teacher Note: Circulate and check for correct function syntax, proper indentation, and understanding of when to call the function.
๐ŸŽฏ Kahoot-Style Function Quiz

Test Your Function Knowledge!

5 questions โ€” how many can you ace? ๐Ÿ†

๐ŸŽช Closure โ€” Exit Ticket

Function Creator Challenge

Demonstrate mastery by creating your OWN custom Karel function!

Create Your Function

Ideas: climb_stairs(), build_tower(), collect_all_balls()

๐ŸŽ‰ Great work, Engineer! Screenshot this and submit to Canvas.
โœ…

Success Criteria

  • Function has correct syntax: def, colon, indentation
  • Function solves a specific problem
  • You can explain its purpose in your own words
๐Ÿ—ฃ๏ธ

Final Question

"What did you learn today about thinking like a software engineer?"

Be ready to share with the class!

๐ŸŽ‰ Lesson Complete!

You're a Python Engineer Now!

You learned the DRY principle, function syntax, and applied it in CodeHS โ€” just like real engineers do!

โœ๏ธ

Writing

Exit ticket, Canvas responses, function comments

๐Ÿ”

Inquiry

Guided questions, problem-solving Karel

๐Ÿค

Collaboration

Fireman Karel partner work, physical turn-left test

๐Ÿ“

Organization

5-step engineering process, structured code

๐Ÿ† Bonus Challenge: Find another repeated pattern in your CodeHS code and turn it into a function. Show your teacher for extra credit!

๐Ÿ Python Functions ยท CodeHS Unit 1.3: Karel Can't Turn Right

CodeHS.com ยท WICOR/AVID Aligned ยท 45โ€“60 min ยท Quia Page

Last updated  2026/02/17 20:02:44 PSTHits  66