CS110A Week 8 Day 2 lesson on 10/08/2026
Watch on YouTube →
Overview
Indika Walimuni builds a Python Turtle exercise that draws circles with random radii and positions, then explains how functions support code reuse and how random RGB values could add color. The lesson moves through Python types and string immutability, floating-point limits and formatting, the `math` module, and modulo arithmetic, before reviewing course assignments and introducing a three-digit digit-swapping problem.
Key takeaways
- A Turtle circle can be randomized by independently selecting its x and y coordinates and radius with `random.randint`, then moving with the pen raised before drawing.
- Functions reduce duplicated code and provide abstraction; a loop is the natural way to scale the five-circle example to 100 repetitions without writing 100 calls.
- Python strings are immutable: indexed character assignment raises a `TypeError`, while lists allow item assignment.
- Python integers expand with available memory, but floating-point values have a finite range, making overflow handling important in reliability-sensitive software.
- Modulo returns a remainder, so pairing `% 60` with floor division by 60 converts total minutes into leftover minutes and complete hours.
- Formatting pi to two decimal places produces a string such as `3.14`; use `float()` when a numeric value is needed for further calculations.
Chapters
- The task is to draw circles whose radii and locations are random, building on an earlier Turtle circle-drawing function.
- The proposed function takes a color as input; the output is a set of circles.
- Walimuni imports Python's `random` module and demonstrates `randint(20, 100)` for a possible circle radius.
- `randint` includes both endpoints, and repeated runs can return different values.
- The plan is to move the Turtle to a random location, generate a random radius, and draw one circle.
- The example uses random x and y coordinates from about -200 to 200 and a radius from 0 to 100.
- The Turtle lifts its pen before moving and lowers it before drawing.
- A function describes drawing a circle with a random radius at a random location, then a second function calls it five times.
- The function's public interface, including its descriptive documentation, helps readers understand code without inspecting every line.
- The first run reveals a radius-argument mistake that produces dots; correcting the radius lets Turtle draw circles.
- A random RGB color can be formed by independently choosing red, green, and blue integer values from 0 to 255.
- Turtle fill coloring uses the RGB values with the same `begin_fill` and `end_fill` approach used for named colors.
- Functions enable code reuse and abstraction, while a loop, taught later in the course, would avoid manually repeating a drawing 100 times.
- The built-in `type()` function reports types such as `int` for an integer and `str` for a string.
- Assigning 20 to a variable previously holding 10 is reassignment, not a test of whether the integer object is mutable.
- Python manages object memory automatically; `del x` removes the name `x`, so later access raises a `NameError`.
- The example tries to replace the first character of the string `Indika` using an index assignment.
- Python raises a `TypeError` because strings do not support item assignment and are immutable.
- Walimuni contrasts strings with lists, which allow item changes, and says the class will study them in more detail later.
- After the break, Walimuni recommends projects students could showcase on a resume or GitHub.
- Suggested examples include an infographic, a presentation, and visualizing a dataset related to a student's interests.
- A decimal such as a floating-point value is a float literal, while scientific notation uses `e` to indicate an exponent.
- The chemistry example identifies Avogadro's number as approximately 6.023 × 10²³ particles per mole.
- Python integers can grow as far as available memory permits, unlike fixed-width integer types in languages such as C++ or Java.
- Floating-point values have a finite range, with a maximum on the order of 10³⁰⁸; calculations beyond the supported range can overflow.
- Walimuni connects overflow safeguards to reliability risks in systems such as flight controllers.
- The built-in `dir(math)` lists names available in Python's `math` module, including trigonometric functions and constants.
- Module attributes are accessed with dot notation, as in `math.pi`.
- The example prints the value of pi from the module.
- A formatted numeric value uses a format specifier to display pi rounded to two decimal places, producing `3.14`.
- The formatted result is a string, even though it looks like a number, so it cannot directly be used as a numeric value.
- Passing the formatted string to `float()` converts it back to a floating-point number.
- The `%` operator calculates a division remainder, not a percentage; for example, `23 % 10` evaluates to 3.
- Modulo is useful in coding problems, including calculations based on repeated division.
- Walimuni relates the operator to finding remainders during binary conversion.
- Floor division by 60 finds the number of complete hours in a total number of minutes.
- Modulo 60 finds the remaining minutes; for an input of 234 minutes, the result is 3 hours and 54 minutes.
- A practice problem uses modulo to find the minutes left after traveling as many complete miles as possible.
- Students choose an operation from the assignment, use the provided code template, and share a link to their demonstration.
- The written post should explain the operation's intention and identify its operands.
- For `23 % 10`, the operands are 23 and 10; because there are two operands, modulo is a binary operation.
- The SciLab driving-cost exercise uses fuel efficiency in miles per gallon, gas cost, and distance to calculate fuel expense.
- Students complete the supplied function and can earn points for including a docstring.
- The programming assignment is a money-register calculator with code checks and rubric points for a plan; students should include their LMS IDs.
- Walimuni publishes a first word-based problem in module six, separate from the Turtle exercises.
- The input is a positive three-digit integer, and the task is to swap its first and last digits.
- Students may need to refresh the module view to see the newly published problem.
Transcript excerpt
0:00 Morning guys. It's our agenda today. So, we're going to first solve that. All right. So, I already copied it over here, okay? So, basically, um not this one, guys. I think running Nothing will come up. All right. So, um this is the problem statement. Basically, we are asked to you know, randomly create a set of cycles. Okay? The radius is random, and also the the location also random. I remember we already um draw a like, you know, wrote a function to
0:46 uh draw circles, right? So, uh we're going to reuse that code, guys, okay? So, um and then then um build on top of this, okay? That's actually usual practice in in programming, okay? Okay, so, but um let's do some practice first with this random number generator thing, right? So, um but I um yeah, so let's uh for the understand part, right? Let's start that, and then then we'll do some practice with the random numbers, and then then I use it, okay? So, All right. Um
1:47 So, what is the um Let me write it here. What are the inputs to our function? Inputs? Let's first figure out that. What are the inputs? Given color, right? Color. Uh anything else? No, right? Only the color, right? Yeah. So, the everything else random. So, we basically do the those figuring out inside our code. So, the word is given which recognizes the color is an input. So, um
2:34 the color. And this could be um uh I mean, let's say anything. We can learn about color can be coming as RGB values, integer values, or strings, okay? So, I would say uh like letters, like green, right? STR or an RGB int, red, green, blue value int, okay? Um integer value. And then that's actually
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
Related notes
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.