CS110A Week 7 Day 1 lesson on 09/29/2026
Watch on YouTube →
Overview
Indika Walimuni teaches Python function design through an equilateral-hexagon Turtle exercise, showing how parameters, clear function interfaces, and reusable code make programs more flexible and readable. The class also covers function calls and return values, introduces a midterm project, and applies the lessons in a flower-drawing activity and live debugging.
Key takeaways
- An equilateral hexagon’s Turtle turn is 60°, calculated as 360° divided by six sides; raising the pen before `goto(x, y)` prevents an unwanted line to the starting point.
- Passing one Turtle object into a drawing function avoids repeatedly creating graphical objects and keeps the drawing routine reusable.
- Function parameters generalize behavior: a single square function with a `size` parameter replaces separate functions for different fixed side lengths.
- A function definition does not run until it is called, and a call that returns a value can be embedded in a larger expression or assigned for later use.
- Readable function names and docstrings communicate a function’s public interface, while reuse reduces duplicated code and supports modular program development.
- The midterm project allows roughly four weeks and recommends exploring practical formats such as a GitHub-hosted résumé or a data-analysis report rather than defaulting to an essay.
Chapters
0:00
Identify the Hexagon Function’s Inputs and Output
- The equilateral-hexagon problem takes a side length, fill color, and starting point as inputs.
- Represent the side length and the point’s x- and y-coordinates as integers; represent the fill color as a string.
- The required output is a filled equilateral hexagon drawn at the specified location.
6:00
Sketch the Hexagon and Derive Its 60-Degree Turn
- The Turtle must first travel from its initial position to the given coordinate rather than draw from the origin.
- For a six-sided polygon, calculate the turn as 360° divided by 6, giving 60° after each side.
- Sketching the path by hand exposes the need to move to the starting point without drawing a connecting line.
11:30
Plan Turtle Pen Movement and Repeated Hexagon Steps
- Raise the Turtle’s pen before moving to the supplied x- and y-coordinates, then lower it before drawing.
- The algorithm alternates moving forward by the side length with turning left 60°.
- Six sides require repeated steps; the class notes that loops will later replace manually duplicated instructions.
18:00
Pass One Turtle Object into the Drawing Function
- The function receives a Turtle object along with the drawing’s other parameters.
- Reusing one Turtle avoids creating a new graphical object for every drawing; the earlier rectangle example could create eight turtles for eight rectangles.
- The main program creates the Turtle and passes it into the function call.
23:30
Document the Hexagon Function’s Public Interface
- The function’s docstring should describe its parameters, including side length, fill color, and x/y location.
- The function definition and its docstring form its public interface: readers can understand its purpose without inspecting the implementation.
- The code uses Turtle methods such as `up()`, `goto()`, `down()`, `forward()`, and `left()` to implement the planned steps.
27:30
Run and Debug the Trinket Turtle Program
- The initial run fails because the Turtle module was not imported; adding `import turtle` resolves that issue.
- Further errors come from a typo and indentation problems in copied code, illustrating the need to inspect exact lines rather than rely only on vague error messages.
- After correcting the code, the Turtle draws the hexagon at the chosen location with a side length of 100.
33:00
Review Hexagon Improvements and Python Data Types
- An optional improvement invites students to create a honeycomb or a flower pattern from hexagons for two extra points.
- The code includes integers such as the side length and coordinates, strings such as the color `red`, and a Turtle object.
- Function calls and literal values are examples of expressions used in the program.
35:30
Why Polygon Functions Need Parameters and Loops
- A 100-sided polygon would require roughly 200 manually written movement-and-turn instructions if each side were coded separately.
- Generalizing the drawing to any number of sides requires the side count to control the turn angle and the number of repetitions.
- The lesson uses this tedious repetition to motivate learning loops in a later course module.
45:00
Midterm Project: Choose a Topic, Format, and Deliverable
- The midterm is a project rather than an exam, with about four weeks to complete it and an estimated maximum effort of 10 hours.
- Students choose a topic and subtopic or propose an original project for approval before starting.
- Suggested formats include a presentation, recorded talk, infographic, concept map, essay, or data-analysis report; the instructor recommends trying a new format rather than defaulting to an essay.
- A GitHub-hosted online résumé is highlighted as practical software-industry experience, and the instructor offers one-on-one help.
52:00
Code.org Demonstrates Function Parameters with Turtle Drawings
- The class watches a Code.org lesson showing why separate fixed-size square functions duplicate code.
- A `size` parameter lets one square-drawing function handle different side lengths, such as 50 or 100 pixels.
- Additional parameters can customize features such as line color, with one argument supplied for each parameter in a call.
59:00
Separate Function Parameters from Keyboard Input
- A parameter is one way to provide input to a function; Python’s `input()` function is specifically for reading from the keyboard.
- The hexagon function receives values through its parameter list rather than collecting them internally with `input()`.
- Python Tutor is recommended for tracing code execution, with green marking the executed line and red marking the next line.
1:03:00
Trace Function Definitions, Calls, and Nested Execution
- Defining a function does not execute its body; execution begins when the program calls it.
- A function can call another function, as in a pizza-calorie calculation that calls a circle-area calculation.
- Execution enters a called function, runs its body, and returns to the line where the call occurred.
1:08:00
Use Function Calls as Expressions and Return Values
- A function call that returns a value can appear inside a larger expression, such as multiplying a returned circle area by a calorie-per-area value.
- The returned value becomes part of the caller’s calculation or can be assigned to a variable.
- The class contrasts functions that return values with actions such as Turtle’s `down()` method, which does not require a parameter.
1:10:00
Write a Fruitful Function That Multiplies Its Parameter
- Students define `calculate_result` with one parameter and return 5.2 multiplied by that parameter.
- A function that returns a value is described as a fruitful function; one without a return value is called non-fruitful.
- The example uses an f-string to format output and a `.2f` format specifier to display two decimal places.
1:16:00
Explain How Functions Improve Readability and Reuse
- A descriptive function name and docstring make the hexagon’s purpose clearer than a block of Turtle commands alone.
- Reusable functions support modular development: a rectangle-drawing function can help construct a larger picture.
- Calling one function repeatedly avoids the hundreds of duplicated lines that could otherwise be used to draw eight rectangles.
1:19:30
Start the Flower Assignment with Turtle Circles
- The new activity asks students to define a circle function and use circles as petals in a flower.
- Students are directed to check the Turtle documentation for built-in circle-drawing methods.
- The assignment follows the course’s analysis, plan, and implementation approach and includes five questions.
1:22:00
Collaborate on the Flower and Format Code Submissions
- Students work in teams and troubleshoot locating the activity in the course modules and refreshing the module view.
- The instructor demonstrates switching a code submission from paragraph formatting to preformatted text so indentation and code layout display correctly.
- Students are encouraged to add colors and extend the drawing toward a complete flower or a three-hexagon honeycomb.
1:30:00
Debug a Function by Returning and Printing Its Result
- A student’s operator-demonstration function is corrected to receive its number through a parameter rather than `input()`.
- The subtraction operation must be returned, and the function call must supply an argument to avoid a missing positional argument error.
- Wrapping the function call in `print()` displays the returned result; adding a second parameter can generalize subtraction to two inputs.
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, indika walimuni.