CIP 2025 - Section Week 5
CIP 2025 - Section Week 5
Section!
Week 5
Slides by Cameron Mohne and Maggie Lee
Agenda
1. 2. 3.
Section Problem:
Check-in Recap
Random Circles
Before we start...
In breakout rooms:
Grab the closest thing to you and try to sell it to your
partner.
As a group, one-by-one:
What did you try to sell?
Questions?
Before we jump into the recap, are there any
questions?
Lecture Recap
Recap -
Functions 2.0
Functions 2.0
Returns
Similar to parameters, but in
the reverse direction! We use
return statements to pass def function_one():
data from a function to input()
name = input(“Enter your name: ”)
wherever it was called. returns
data for
def input(prompt):
One example is the input() you to use,
... # Some code
function that you’ve been wherever
return user_input
using! Whenever you have a you called
function that returns it from!
something, you usually want
a variable to store that data!
Recap -
Graphics
Canvas
The canvas is a fun way
for us to visualize and
interact with our code in
a somewhat similar way
to Karel!
(0,
0)
Canvas
Remember how pixels are
laid out: starting at (0, 0) (150, 150)
for the top left and
increasing in x/y-values
as you go right/down
respectively
(300, 300)
y1
Canvas
To draw something, we need to use x1
40px
four parameters. These numbers (0,
represent the coordinates of the 0)
40px
two points used to draw the image.
(40,
Since the function is a part of our 40)
canvas, we use our canvas
followed by a period and then the x2 y2
X2
0
End Goal
Our program takes in a blank
canvas and then draws 20 Example Output
circles at random Canvas
positions with random
colors on the canvas.
Problem Details
Canvas Colors
The canvas is created We provide a function
for you already with that returns a random
some functions color
provided
Canvas Circle
Details Details
We give you the
Canvas width/height diameter size of the
are provided as global circles and the
variables number of circles to
make
Pre-code Discussion
Say we want to make a single circle, how would we
do that?
Hi, I’m a
circle!
And
single!