CS110A Week 5 Day 2 lesson on 09/17/2026
Watch on YouTube →
Overview
Indika Walimuni teaches CS110A students to solve a turtle-graphics problem by writing a numbered English algorithm first, then translating it into Python to draw an equilateral triangle with 100-unit sides. The lesson connects reusable functions and their public interfaces to abstraction, demonstrates keyboard input and type conversion with `input()`, `int()`, and `float()`, and distinguishes syntax, runtime, and logical errors through Python examples.
Key takeaways
- Writing a numbered algorithm in English before translating it into Python separates problem solving from coding syntax and makes complex tasks easier to approach.
- A reusable triangle function should accept the side length as an argument; collecting input in the main program keeps the drawing function flexible and reusable.
- Python's `input()` returns a string, so numeric responses need conversion with `int()` or `float()` before arithmetic.
- A turtle must turn 120 degrees between the sides of an equilateral triangle because the turtle follows the exterior angle, not the triangle's 60-degree interior angle.
- Syntax errors stop code from being parsed, runtime errors occur during execution, and logical errors produce incorrect results despite successful execution.
- The Eisenhower Matrix offers a study-planning method: do urgent and important work, schedule important work, delegate urgent lower-priority tasks, and eliminate distractions.
Chapters
- A function's public interface describes what it should do, so users can understand it without reading the implementation.
- The `main` program calls a function to make its code run; defining a function alone does not execute its drawing steps.
- A turtle function can be tested by running the main program and checking whether it draws the expected square.
- The problem statement can be copied into a triple-quoted string literal as documentation within the Python file.
- Triple single quotes and triple double quotes both enclose multiline text.
- Keeping the prompt beside the code avoids repeatedly switching tabs to check the requirements.
- Walimuni recommends solving programming problems in familiar English before translating them into Python syntax.
- Numbered steps make the algorithm's sequence explicit, much like sequentially numbered Python code lines.
- Breaking the work into problem-solving and translation reduces the cognitive load of thinking, coding, and typing at once.
- The triangle algorithm begins by choosing a side length of 100 units and creating a turtle.
- The turtle moves forward by the side length, then turns left 120 degrees before drawing each following side.
- A hand-drawn diagram helps track the turtle's position and heading; the 120-degree turn is the exterior angle corresponding to the triangle's 60-degree interior angle.
- The English steps map to Python turtle operations: create a turtle, move forward by `length`, and turn left by 120 degrees.
- The turtle module's constructor creates a turtle object, and dot notation accesses module attributes such as the creation function and speed setting.
- Domain knowledge about equilateral triangles supplies the geometry needed to choose the turn angle.
- A function definition does not draw anything until the program calls the function.
- The triangle code draws three equal sides by repeating forward movement and 120-degree left turns, then returning to the starting corner.
- Walimuni compares defining a function without calling it to building a microwave that nobody has used yet.
- A function hard-coded to draw only a 100-unit triangle works, but requires code changes for a different size.
- Changing the side length in the implementation for every new triangle makes the function inflexible.
- The microwave analogy illustrates the design problem: a useful tool should accept different inputs rather than serve only one fixed case.
- Passing `length` into the triangle function lets one implementation draw triangles of different sizes.
- Calls using values such as 200 and 50 reuse the same drawing steps without modifying the function body.
- A function is a named set of code that can be invoked repeatedly, connecting function reuse to the abstraction introduced earlier in the course.
- The triangle code uses integers such as 100 and 120, a multiline string literal for documentation, and a turtle object created by the module.
- Values, variable names, and function calls can each be expressions; assignment statements combine expressions to store results.
- The `import` statement is distinct from an assignment statement and brings a module into the program.
- The lesson identifies `import` and `def` as Python keywords used for importing modules and defining functions.
- Keywords cannot be reused as variable names; attempting to assign a value to `def` produces a syntax error.
- The class reviews code-posting expectations and notes that turtle functions can also change line color, fill color, and thickness.
- Students can save a copy of the class Google Colab notebook to their school Google Drive and revisit dated class code.
- Canvas notifications can be routed to a private email, and automatic forwarding from a school account can help students avoid missing announcements.
- The Eisenhower Matrix sorts tasks by urgency and importance: do urgent-important tasks, schedule important tasks, delegate less-important urgent tasks, and eliminate low-priority distractions.
- The `input()` function prompts a user to enter a value through the keyboard, such as an age.
- In Google Colab, running a cell with `input()` displays a box where the user enters a response.
- Students are shown how to save a personal copy of the class notebook so their code changes persist.
- A value entered with plain `input()` is a string, even when the user types digits.
- Multiplying the string `'45'` by 5 repeats the text rather than calculating 225; `type(age)` reveals the string type.
- Wrapping input in `int()`, as in `int(input(...))`, converts numeric text to an integer; prices with decimal places should use `float()`.
- The program can collect a triangle's length with `int(input('Enter length: '))` and pass that value to the drawing function.
- Walimuni's design rule is to gather user input in the main program rather than inside a reusable drawing function.
- Keeping input outside the function preserves a clear public interface and lets other code supply a length without requiring keyboard interaction.
- A guided challenge has students copy code into an activity, submit it, inspect the autograder result, and complete successive levels.
- The next lesson section introduces errors, beginning with syntax errors caused by code that violates Python's grammar.
- The class uses editor feedback, such as a warning for an unmatched parenthesis, to identify malformed code.
- Syntax errors prevent code from running, such as an unmatched parenthesis or two `print` statements placed together without a separator.
- Runtime errors occur during execution: converting nonnumeric text to a number causes a value error, and dividing by zero causes a zero-division error.
- A name error occurs when code uses an undefined variable, as with `price` before it has been assigned a value.
- Python indentation is part of code structure; function-body lines should be consistently indented.
- A salary calculation that multiplies by 5 instead of using a 5-percent rate produces an incorrect result even though the program runs.
- Correcting the calculation to multiply by 5 and divide by 100 computes the increase; multiplying by 105 and dividing by 100 gives the new salary directly.
- Students begin a paired turtle exercise to draw a rectangle pattern using the earlier triangle and square drawing techniques.
- Walimuni collects attendance and discusses an honors option involving a small, class-relevant addition rather than a full-scale project.
- Students are advised that honors requests must be submitted through the college system and that the plan should be finalized during the month.
- The closing debugging exchange checks that the rectangle template uses the correct turtle object name.
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.