Making a program interactive
Until now your turtle programs have done exactly the same thing every single time you ran them. That changes today.
An algorithm can be designed to accept information, called input. The program processes that input and produces output — the result. Giving the user choices is what makes a program feel personal instead of canned.
The = is the assignment operator. The expression on the right is evaluated,
and the result is stored in the variable on the left. It does not mean "equals" the way it does in math.
a ← expression,
user input is INPUT(), and printing is DISPLAY(expression).
Same ideas, different notation.
💻 Run the program
Type an answer in the terminal below and press Run, exactly like the Python terminal in the code editor.
🧠 Quick check
In the statement user_name = input("What is your name? "), what actually ends up stored in user_name?
The trap in every input program
This program is supposed to estimate the year you were born. Read it, then run it.
Click a statement, then click the data type it gives the variable x.
string
integer
The circle method does more than circles
circle(r, e, s) takes up to three parameters:
- r — the radius. Required.
- e — the extent: how many degrees of the circle to draw. 180 gives a semicircle. Leave it out and you get the whole circle.
- s — the steps: how many straight segments to draw it with. 5 steps makes a pentagon.
Move the sliders and watch what happens. The code updates as you go.
The turtle starts at the green dot facing east.
Set the sliders above so the drawing matches each target, then click Check. Radius is up to you.
Filling a shape with color
Three methods work together, and they only work in one order:
.fillcolor(c)— names the color to fill with. Must come first..begin_fill()— marks where the shape starts..end_fill()— marks where it ends, and fills it in.
Click the four statements in the order that draws a filled circle.
Available statements:
Your program:
✏️ Pen up, pen down
You want to draw two separate circles with a gap between them. Which program does it?
Everything you have typed all year has this same shape. Click each colored piece to find out what it is — find all 4.
📄 The blueprint and the thing
A class is a design — a blueprint or a recipe. An object is one actual thing built from that design, called an instance.
Objects have properties (characteristics — what it is) and methods (actions — what it does).
property
method
🎨 Plan your picture
Design a picture you would like to draw with Python turtle — something that would brighten someone's day. Sketch it in your notebook first, then plan it here before you write any code.
Show what you know
Answer all 8 questions, then click Grade my exit ticket. One retry allowed.
📝 Computer Science Notebook
- Input is information given to a program; output is the result it produces.
- The assignment operator
=stores the value of the expression on the right into the variable on the left. College Board writes ita ← expression. input()always returns a string, even if the user types a number. Useint()to convert it before doing math.- A substring is a part of an existing string.
- Comments start with
#. They are not executed — they make code readable for the next person. circle(r, e, s): radius, extent in degrees, and number of steps. Steps turn a circle into a polygon.fillcolor(c)thenbegin_fill()… shape …end_fill().- A class is the blueprint; an object is an instance built from it. Properties are characteristics, methods are actions.
🤔 Conclusion questions
- What is the difference between the input and the output of a program, and how can one affect the other? Give an example using Python code.
- Is there only one way to solve a problem? Explain and give an example using Python turtle.