CS110A Week 6 Day 2 lesson on 09/24/2026
Overview
Indika Walimuni introduces CS110A Chapter 5 by completing a CodeCheck name-tag exercise and teaching how user-defined functions organize reusable code. The lesson distinguishes keyboard input from function parameters and printing from returning, demonstrates exact-output debugging and clean-code practices, then applies functions to a pattern exercise and an equilateral-hexagon drawing task.
Key takeaways
- Collect keyboard input in the main program and pass it into a function as parameters; this keeps the function independent of keyboard interaction.
- Automated output checking is most effective when students compare actual and expected text line by line, correcting ordering, spaces, punctuation, and literal labels.
- A function definition creates reusable behavior, while a function call executes it; naming repeated work prevents copying large blocks of turtle code.
- Python’s print() displays a value but returns None, so a function must use return when its result needs to be used in another expression.
- Readable names and self-explanatory code make programs easier to maintain; comments should be used thoughtfully because outdated comments can mislead future readers.
- CodeCheck supports repeated submissions and sends automated results to Canvas, but the assignment plan still matters because it accounts for 20% of the grade.
Chapters
- The exercise asks students to write a function that produces a name tag from first name, last name, title, and section information.
- Indika Walimuni gives students about 10 minutes to read the detailed instructions and compare the required output format.
- The task separates input collection in the main program from name-tag generation in the function.
- CodeCheck connects submissions and grades to Canvas similarly to zyBooks, but requires no separate user account or payment.
- Students copy their unique course LMS ID into CodeCheck so Canvas can identify their work.
- Indika demonstrates entering a full name and LMS ID in the student workflow.
- Students identify the four inputs (first name, last name, title, and section) from the prompt before writing the function.
- The specified output order determines how the main program should prompt for and collect the information.
- The initial problem page contains a mismatched instruction; Indika corrects it by using the actual name-tag prompt.
- The Python input() function reads from the keyboard, while the broader idea of function input refers to values passed as parameters.
- Collect keyboard input in the main program, then pass those values into the function rather than calling input() inside it.
- A function docstring should describe what the function does and refer to the inputs it receives.
- The function prints the name-tag details using its parameters; the main program handles prompts and input collection.
- Students arrange first name, last name, title, and section according to the requested format.
- The exercise provides the function call so students can focus on implementing the function body.
- CodeCheck displays actual output alongside expected output, allowing students to locate formatting differences.
- The first test reveals that title and section information are misplaced because the prompts and collected values are in the wrong order.
- The debugging process proceeds by comparing each output line rather than guessing at changes.
- An empty print() call can create a blank line when the name-tag output needs to begin on a new line.
- Indika adds the missing comma and the literal label "section" after comparing the actual and expected strings.
- A syntax error caused by an extra comma is fixed by checking the reported line and nearby code; the corrected program passes.
- CodeCheck reports automated results to Canvas, but the assignment plan is separately worth 20% and receives instructor review.
- Students can submit repeatedly, use feedback to correct errors, and resubmit for regrading.
- Class troubleshooting covers missing brackets, indentation errors, alignment, and the common four-spaces-per-indent convention.
- Indika frames programming as learning a language through immersion and practice, comparing Python learning with studying Spanish or Mandarin.
- Natural languages such as English evolve without one inventor; formal languages such as Python have defined structures and creators.
- The A-M-P-E-R problem-solving approach helps students connect familiar language concepts to Python.
- A function gives a name to related code that performs one task, allowing the name to stand in for the full procedure.
- Indika removes the rectangle-drawing function and uses pass as a Python statement that does nothing while leaving a valid function body.
- The demonstration sets up a comparison between reusable function calls and repeatedly writing the same turtle instructions.
- The embedded software-development talk argues that programmers spend far more time reading code than typing it, so readability can reduce debugging and maintenance time.
- Its advice includes taking responsibility for code quality and using meaningful variable names and function names that express intent.
- Comments can become misleading when code changes; prefer self-explanatory code where possible, while retaining comments for details such as third-party API behavior.
- The talk recommends leaving existing code cleaner than you found it, for example by improving a variable name or splitting an oversized method.
- Without a function, drawing multiple rectangles requires repeating the turtle commands and manually setting values such as color, position, length, and width.
- Indika runs a rectangle example and then adds another drawing, showing how repeated code and adjusted parameters become cumbersome.
- A named function makes the single task reusable and avoids copying the full set of drawing instructions for each rectangle.
- The function definition creates the reusable operation; a later function call executes it.
- Indika compares defining a function to manufacturing a microwave and calling it to using the appliance to warm pasta.
- Python function definitions begin with the def keyword, use a function name, and indent the function body by four spaces or one tab.
- A return value is the result a function provides after doing its work, comparable to warmed food coming out of a microwave.
- Python’s return keyword sends a value back to the code that called the function.
- Printing output and returning a value are different operations, a distinction students will apply in the next exercise.
- The class writes a square function and first uses print() to display the square of a number such as 2.
- Calling the function inside another square operation raises a TypeError because the first call provides no usable numeric result.
- Checking type(square(2)) reveals NoneType: print() displays the number but does not return that number to the calling expression.
- Replacing print() with return makes the square function produce a numeric result that another operation can use.
- Squaring the returned result of squaring 2 gives 16, demonstrating that returned values can participate in larger expressions.
- Indika recommends returning values when a function’s result will be used elsewhere, and printing a function call in the main program when the value needs to be displayed.
- The get_pattern exercise requires a function to return a five-character string, then calls it twice and prints both results.
- The hexagon task begins with starter code copied into Trinket; students are asked to draw an equilateral hexagon themselves.
- Indika shows students how to bookmark their Trinket workspace before replacing its contents with the starter code.
- Indika announces plans for a City College REU (Research Experiences for Undergraduates) club focused on introducing students to research internships.
- The club aims to invite internship hosts as speakers and provide guidance on how to apply, drawing on Indika’s experience supporting students through a California workforce program.
- Students can express interest in the General Q&A forum and volunteer as a committee liaison for their class.
Transcript excerpt
0:00 So this is our agenda today. Okay. So um remember that code check problem. So we're going to actually start with that. Okay. So so let's go to that. So let's write here. Um yeah this one. So this is the problem. Okay. something. What is that? Okay, so let me uh refresh this. Okay, there you go. Okay, so um so um I actually you know may make it uh
0:52 clear the expected output. So like print it like that. Okay, so that way it's clear to you guys. Okay, what to uh what to get and then in fact code check actually um will try to print it like this way. Okay, so um basically the problem statement so there are like you know some things to uh read. Okay, so um take some time take 10 minutes to read this through because this is our first time using this right. So um and there there are a lot of clear instructions and then since there are a lot of instruction there's a lot to read. Okay. So but you know I I promise the the amount of things to read going to go um decrease. Okay. So uh in this case just we are printing a name tag. Okay. And
1:41 then this is the uh function you have to write. Okay. And then um uh in the um right you have to uh input these three in the main program. So they those are also instructions right. So collect input in the main program and there's a reason for that. We usually don't write uh collect input in our function we write. Okay. So it's because uh user has data and then user runs the main program. Okay. And then main program inside you call our function we write.
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
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.