C. shape(): Changing the Turtle Shape
๐ฏ Learning Goals
By the end of this lesson, you'll be able to:
- โ
shape()You can use a function - โ Understands why strings need quotation marks
- โ Can learn about various shape options
โก 30-Second Challenge
Run the code below and try changing the shape!
Did it work? Let's learn more about it below!
Core Concepts
What is shape()?
shape('turtle')sets the turtle's shape.
โ ๏ธ Quotation marks matter!
'turtle'like Quotes You need to put the shape name inside.
โ Wrong Code
Error: PythonturtleIt tries to find it as a variable
โ Correct Code
Normal: Python'turtle'It recognizes it as a string
Available shapes
| Code | Shape | Description |
|---|---|---|
'turtle' |
๐ข | Turtle (default) |
'arrow' |
โก๏ธ | Arrow (to show direction) |
'circle' |
โซ | Circle |
'square' |
โฌ | Square |
'triangle' |
๐บ | Triangle |
Try Visual Coding
Mission
Add a "shape" block and pick a different shape from the dropdown!
# Add blocks and the Python code will show up here...
Add blocks and the flowchart will show up here...
Example Code
What Happens
An arrow shape appears on the screen!
Quiz
Quiz: using quotes
What should you put in the blank to set the turtle shape?
t.shape(____)
Show Answer
Answer: 'turtle'
Strings must be wrapped in quotes!
๐ง Debug Clinic
Problem: a NameError occurs!
โ Wrong Code
Cause:shape(turtle) - You forgot the quotes!
โ Correct Code
Fix:shape('turtle') - Add quotes!
Try Coding It Yourself
Take what you learned with the blocks and write it yourself in Python code!
Change shape
t.shape()Change the turtle's shape with it.
Example Answer
Result: an arrow shape appears on the screen!
shape() syntax practice
- Change to an arrow:
t.shape('arrow') - Turning it into a circle:
t.shape('circle') - A string QuotesWrap it with (
'Or")
Review Checklist
- [ ]
shape()You can explain what a function does - [ ] You know why writing shape(turtle) without quotes causes an error
- [ ] You remember at least 3 of the 5 shape options
๐งฉ Key Takeaways
What you learned in this lesson:
| Concept | Description |
|---|---|
| shape() | The function that sets the turtle shape |
| Quotes | The shape name is 'turtle'quotes required, like this! |
| Option | turtle, arrow, circle, square, triangle |