Python (Fall 2026) Module 5-10: A5 Explanation
Overview
Bill Moseley explains Assignment 5, an “advanced calculator” that wraps simple area calculations in a text menu. Users choose rectangle or triangle with R or T; an if/elif/else branch gathers dimensions, converts inputs to integers, calculates area, and gives an error message for unrecognized choices.
Key takeaways
- A menu-driven calculator combines user input with if/elif/else branching to route R to rectangle calculations and T to triangle calculations.
- Rectangle area is calculated as height times width, while triangle area is calculated as 0.5 times base times height.
- The example converts dimension strings with int() before performing arithmetic and uses an f-string to display the result.
- An else branch handles any menu input other than r or t, giving users clear feedback instead of silently doing nothing.
- The sample program does not validate whether dimension inputs are numeric, an improvement Moseley explicitly leaves outside the assignment’s main focus.
Chapters
- Bill Moseley frames A5 as an extension of the A4 calculator: users first choose which calculation to run.
- The example menu offers rectangle area and triangle area, each requiring different inputs and formulas.
- The planned structure includes welcoming the user, presenting choices, branching to a calculator, and exiting gracefully.
- A triple-quoted string displays instructions to type T for triangle or R for rectangle, and input() stores the selection in strChoice.
- An if/elif/else checks for lowercase r and t, while the final else displays an error for anything else.
- Moseley notes that numeric-input validation could be added, but leaves it out to focus on the calculator’s basic functionality.
- The rectangle branch converts height and width to integers and multiplies them; the triangle branch calculates 0.5 times base times height.
- An f-string reports each area, and a closing message thanks the user after either a calculation or an invalid choice.
- Test runs with triangle dimensions 10 and 10 return 50, rectangle dimensions 10 and 40 return 400, and entering hello triggers the error message.
- Moseley identifies the assignment’s core requirements as a clear menu, if/elif/else branching, basic calculations, invalid-choice feedback, and a final exit message.
Transcript excerpt
0:01 So A5, keeping all of that in mind, A5 is called the advanced calculator. Now this is the same type of calculator that we used in A4, where we just said input your number or your two numbers, and then we will do a calculation and present the result. In this case, we're going to allow the user to choose which calculator they want to use. So, an example of this is, maybe I want the user to have the option to calculate the area of a triangle versus the area of a rectangle. Okay. So, I'm going to first, I'm going to ask the user, I'm going to tell the user, you know, welcome to my calculator program. And then I will say, enter one for the, calculate the area of a rectangle.
1:00 Enter two to calculate the area of a triangle. And then once they've chosen, I'm going to, I'm going to use an if and else to branch into different areas where I have to ask them different things for each of those shapes, and then it will use a different formula and print the result. Okay. So, let's take this, let's take this into the code here. And once again, actually, I'm going to, I'm going to save this part because I'll reuse it. Okay. So, first we're going to welcome a user. I'm going to use comments first here. Present the choices.
1:58 Get user input on which calculator, and then we are going to branch to each calculator. And so I'm going to do, first was, one is going to be get rectangle input, calculate rectangle, print results. Okay, so this, I'm going to actually tab those in,
2:52 because that's going to be under the if. And then my else here is going to be the triangle. So get triangle input,
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, Bill Moseley, Ph.D. - Computer Science Educator.