Build a Command-Line Calculator
Write a Python calculator that handles input, math, errors, and loops.
Introduction
30 Second Summary
Every app you use does math behind the scenes. From splitting a dinner bill to calculating a mortgage payment, the logic is the same: take numbers in, do something with them, and show the result.
In this project, you will build an interactive calculator that runs in your terminal. You will write it from scratch in Python, learning how to take user input, perform operations with functions, and handle mistakes gracefully so your program never crashes.
What You'll Build
You will type two numbers and pick an operation, and the calculator prints the answer back instantly. It keeps running in a loop so you can do calculation after calculation without restarting.
By the end of this project, you'll have:
- A working calculator where you type two numbers and an operator, then see the result printed back immediately.
- A program that keeps running in a loop so you can perform multiple calculations without restarting.
- Friendly error messages instead of crashes when you type letters instead of numbers or try to divide by zero.
- Secret Mission: Add a calculation history feature that remembers and displays all your past results.
Are there any prerequisites?
None. This project includes full setup instructions for Python and VS Code. You do not need any prior programming experience.
Before We Start
Before we dive in, let's lock in what you're about to build and why it matters. This is your moment to commit to the project ahead.
Set Up Python and VS Code
Before you can write any Python code, you need two things on your computer: Python itself (which runs your code), and a code editor to write in.
In this step, you'll install Python and VS Code, then confirm they talk to each other. This is the foundation for everything else in the project.
In this step, get ready to:
- Install Python 3.14.6 on your computer.
- Install VS Code with the Python extension.
- Confirm Python runs in the VS Code terminal.
Install Python 3.14.6
Python is the programming language you'll use to build the calculator. You need it installed on your machine so your computer knows how to run the code you write.
- Press Cmd+Space (macOS) or the Windows key (Windows) to open your search bar.
- Type Terminal (macOS) or PowerShell (Windows) and press Enter to open it.
- Check whether Python is already installed by running this command:
python --version
✔️ I see Python 3.14 or higher
Python is ready to go. Skip ahead to the next substep where you'll install VS Code.
ⓧ I see an older version
You have Python installed, but it's an older version. You need 3.14 or higher for this project. Install the latest version by following these steps.
- Open the Python 3.14.6 download page in your browser.
- Scroll down to the files table and click Windows installer (64-bit) to download it.
- Run the downloaded installer.
- On the first screen, check the box that says Add python.exe to PATH.
- Click Install Now and wait for the installation to complete.
- Close and reopen your terminal, then run python --version again. You should now see Python 3.14.6.
Why check Add python.exe to PATH?
PATH is a list of folders your computer searches when you type a command. Without this checkbox, your terminal won't know where to find Python when you type python.
ⓧ Command not found
Python isn't installed yet. Follow these steps to install it.
- Open the Python 3.14.6 download page in your browser.
- Scroll down to the files table and click Windows installer (64-bit) to download it.
- Run the downloaded installer.
- On the first screen, check the box that says Add python.exe to PATH.
- Click Install Now and wait for the installation to complete.
- Close and reopen your terminal, then run python --version. You should see Python 3.14.6.
Why check Add python.exe to PATH?
PATH is a list of folders your computer searches when you type a command. Without this checkbox, your terminal won't know where to find Python when you type python.
Install VS Code and the Python extension
VS Code is a free code editor that gives you syntax highlighting, error detection, and a built-in terminal. The Python extension adds language-specific features like autocomplete.
- Open the VS Code download page in your browser.
- Click the Windows download button (or choose your platform if you're on macOS or Linux).
- Run the downloaded installer and follow the prompts to complete the installation.
Now open VS Code for the first time.
- Press Cmd+Space (macOS) or the Windows key (Windows) to open your search bar.
- Type Visual Studio Code and press Enter to open it.
Next, install the Python extension so VS Code understands Python code.
- Press Cmd+Shift+X (macOS) or Ctrl+Shift+X (Windows) to open the Extensions panel.
- Type Python in the search box at the top.
- Find the extension published by Microsoft (it should appear at the top of the list).
- Click Install.
What does the Python extension do?
The extension adds autocomplete, error highlighting, and a run button for Python files. It also automatically detects which Python version you have installed.
Don't see the Python extension?
Make sure you typed Python in the Extensions search box, not the main search bar at the top of VS Code. The Extensions panel has its own search field.
help me find and install the Python extension in VS Code
Confirm Python works in VS Code
You've installed Python and VS Code separately. This final check confirms they can talk to each other through VS Code's built-in terminal.
- In VS Code, click Terminal in the top menu bar.
- Click New Terminal.
A terminal panel opens at the bottom of VS Code. Before you run the next command, what version number do you expect to see?
- Confirm Python is available by running this command:
python --version
You should see Python 3.14.6 printed in the terminal. That confirms Python is installed, on your PATH, and accessible from inside VS Code.
Seeing command not found or an old version?
If the terminal says the command is not recognized, Python might not be on your PATH. Close VS Code completely, reopen it, and try again. The PATH changes from the installer only take effect in new terminal sessions.
If you see a version older than 3.14, the old Python is still first on your PATH. Reinstall Python 3.14.6 with the Add python.exe to PATH box checked, restart VS Code, and try again.
help me get python --version working in VS Code terminal
Your tools are ready. Next up, you'll write your first lines of Python code and see the calculator do actual math.
Your First Calculation
Your Python environment is set up and working. Time to make it do something.
Before building a full calculator with multiple operations, you need to see Python actually work with numbers. This step gets you from an empty editor to a visible result in under 5 minutes.
In this step, get ready to:
- Create a project folder and your first Python file.
- Write code that asks for two numbers and adds them together.
- Run the program and see the sum printed in your terminal.
Create your project folder
You need a dedicated folder to hold your calculator file. This keeps your Desktop organized and gives VS Code a workspace to operate in.
- Switch to your VS Code terminal and move to your Desktop by running this command:
cd ~/Desktop
- Create a project folder and move into it by running these commands:
mkdir python-calculator
cd python-calculator
- Confirm the folder was created by running:
ls ~/Desktop
You should see python-calculator listed in the output.
Don't see the folder?
Make sure you typed mkdir python-calculator exactly as shown. If you see a "file already exists" message, the folder is already there. Run cd ~/Desktop/python-calculator to move into it.
Help me figure out what went wrong
Open the folder in VS Code
- In VS Code, click File in the top menu bar.
- Click Open Folder.
- Navigate to your Desktop and select the python-calculator folder.
- Click Select Folder.
Seeing a trust dialog?
VS Code may ask "Do you trust the authors of the files in this folder?" when you open a new folder. Click Yes, I trust the authors to enable all editor features.
Your VS Code sidebar now shows the empty python-calculator folder. This is your workspace for the project.
Write your first calculation
Python can ask the user for input, do math with it, and print the result. You will use three core building blocks: input() to get text from the user, float() to convert that text into a number, and print() to display the answer.
- Create a new file by hovering over PYTHON-CALCULATOR in the Explorer sidebar and clicking the New File icon (a page with a plus sign).
- Type calculator.py as the file name and press Enter.
The file opens in the editor. You are ready to write your first Python code.
- Add the following code to calculator.py:
# Ask the user for two numbers
first_input = input("Enter first number: ")
num1 = float(first_input)
second_input = input("Enter second number: ")
num2 = float(second_input)
# Add the numbers and print the result
result = num1 + num2
print(f"{num1} + {num2} = {result}")
What does this code do?
- input("Enter first number: ") displays a prompt and waits for the user to type something. It returns whatever they type as text (a string).
- float(first_input) converts that text into a decimal number Python can do math with. Without this conversion, Python would treat "5" as a word, not the number 5.
- print(f"{num1} + {num2} = {result}") uses an f-string to plug your variables directly into the output message.
- Save the file by pressing Ctrl+S (Windows) or Cmd+S (macOS).
Before you run this, what do you think will happen? Will the program print something immediately, or will it wait for you to type first?
- Click Terminal in the top menu bar.
- Click New Terminal.
- Run your program with this command:
python calculator.py
The program waits for your input. Type a number (like 5) and press Enter. Type a second number (like 3) and press Enter again.
You should see the result printed back: 5.0 + 3.0 = 8.0.
Seeing an error instead?
- If you see a "SyntaxError" message, check that your quotes and parentheses match exactly. Every opening quote or parenthesis needs a closing one.
- If you see "python is not recognized" or "command not found", Python was not added to your PATH during installation. Reinstall Python and make sure to check "Add python.exe to PATH" on the first installer screen.
- If nothing happens when you run the command, make sure you saved the file first.
Help me debug my calculator.py file
✔️ Awesome, I've got everything!
Great job. Make sure you have saved calculator.py and you can move on.
ⓧ I'd like to double check the full code
Here is the complete calculator.py file. Confirm your code matches this exactly:
first_input = input("Enter first number: ")
num1 = float(first_input)
second_input = input("Enter second number: ")
num2 = float(second_input)
result = num1 + num2
print(f"{num1} + {num2} = {result}")
You just wrote a program that takes real input and produces a real result. Next up, you will turn this single-operation script into a proper calculator with multiple operations by writing your own functions.
Multiple Operations with Functions
In the last step, you got Python to add two numbers together and print the result. That is a great start, but a calculator that only adds is not very useful.
You could copy and paste the addition code and change the operator for each new operation. That would work, but it gets messy fast and is hard to maintain. Functions solve this by giving each operation its own named, reusable block of code.
In this step, get ready to:
- Define four reusable functions for add, subtract, multiply, and divide.
- Let the user choose which operation to perform.
- Use conditional logic to call the right function and display the result.
Define the four operation functions
A function is a named block of code you can call whenever you need it. Instead of writing the math inline, you will define a function for each operation and call it by name later.
- In VS Code, open calculator.py.
- Place your cursor at the very top of the file (above all existing code) and add the following four functions:
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
What does this code do?
Each function takes two parameters (x and y) and returns the result of one math operation.
The def keyword creates a function. The return keyword sends the result back to wherever the function was called.
- Make sure there is one blank line between the last function and your existing first_input line.
- Save calculator.py and run it by clicking the play button in the top-right corner of the editor.
- Enter two numbers when prompted. The program still adds them, which confirms your new functions did not introduce any syntax errors.
Seeing a SyntaxError?
Check that each function starts with def and ends with a colon. The return line inside each function must be indented with exactly 4 spaces.
Also confirm that the functions sit above the first_input = input(...) line, not below it.
help me fix a SyntaxError in my Python function definitions
Replace the addition logic with an operation menu
Right now the program always adds. You will replace that hard-coded addition with a menu that lets the user pick any of the four operations.
- In calculator.py, find these two lines near the bottom of the file:
result = num1 + num2
print(f"{num1} + {num2} = {result}")
- Delete both of those lines and replace them with the following code:
print("\nChoose an operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
choice = input("Enter choice (1/2/3/4): ")
if choice == "1":
result = add(num1, num2)
symbol = "+"
elif choice == "2":
result = subtract(num1, num2)
symbol = "-"
elif choice == "3":
result = multiply(num1, num2)
symbol = "*"
elif choice == "4":
result = divide(num1, num2)
symbol = "/"
else:
print("Invalid choice.")
print(f"\n{num1} {symbol} {num2} = {result}")
What does this code do?
- The five print lines display a numbered menu so the user knows their options.
- choice stores the user's menu selection as a string ("1", "2", "3", or "4").
- The if/elif/else chain checks which number was entered and calls the matching function.
- symbol stores the operator character so the final print line can show the full equation.
- Save calculator.py.
Seeing an IndentationError?
Every line inside an if, elif, or else block must be indented with 4 spaces. Make sure result = add(num1, num2) and symbol = "+" are both indented under if choice == "1":.
help me fix an IndentationError in my if/elif/else block
Run and test each operation
Before you run the program, think about what you expect to happen. If you enter 10 and 3, then choose multiply, what should the output look like?
- Run calculator.py by clicking the play button or typing this in the terminal:
python calculator.py
- Enter 10 as the first number and 3 as the second number.
- Choose option 3 for multiply.
You should see:
10.0 * 3.0 = 30.0
- Run the program a few more times and try each operation (add, subtract, multiply, divide) to confirm they all produce the correct result.
Getting a NameError for symbol?
If you enter a number other than 1 through 4 for the operation, the else branch runs but never assigns symbol or result. Make sure you are choosing 1, 2, 3, or 4.
If a valid choice still fails, check that your elif lines compare against strings ("2", "3", "4") not integers.
help me debug a NameError in my Python calculator
✔️ Awesome, I've got everything!
Great. Double check you have saved calculator.py and all four operations return correct results.
ⓧ I'd like to double check the full code
Your calculator.py should have these sections in this exact order. Scroll through your file and confirm each one is present:
- Four function definitions at the top: add, subtract, multiply, divide.
- Two input() lines asking for first and second numbers, each converted with float().
- Five print lines showing the operation menu.
- A choice = input(...) line.
- An if/elif/else block that calls the correct function and sets symbol.
- A final print line showing the equation and result.
Your calculator now handles all four basic operations. Next up, you will find out what happens when something goes wrong and learn how to handle it gracefully.
Handle Errors Gracefully
Your calculator works perfectly when you feed it good input. But what happens when someone types "hello" instead of a number, or tries to divide by zero?
Right now, those mistakes crash the entire program with an ugly error message. Real programs handle mistakes gracefully. In this step, you will crash the program on purpose, see what goes wrong, and then fix it.
In this step, get ready to:
- Crash the program deliberately with bad input to see the error messages.
- Add error handling so the program prints friendly messages instead of crashing.
- Test the fixes to confirm everything works.
Crash the program on purpose
Before fixing anything, you need to see what "broken" looks like. You are going to deliberately give the program bad input and watch it crash.
What do you think will happen if you type a word instead of a number? Take a guess before you run it.
- Run your calculator by typing this command in the terminal:
python calculator.py
- When it asks for the first number, type hello and press Enter.
The program crashes immediately. You see a wall of red text ending with a line like this:
ValueError: could not convert string to float: 'hello'
What just happened?
Python tried to run float("hello") and could not turn the word "hello" into a number. When Python encounters something it cannot do, it raises an exception and stops the program entirely.
- Run the program again:
python calculator.py
- This time, enter 5 for the first number.
- Enter 0 for the second number.
- Choose option 4 (Divide).
The program crashes again with a different error:
ZeroDivisionError: division by zero
These two crashes are exactly the problems you will fix now.
Fix divide-by-zero and invalid input
You will tackle the divide-by-zero crash first because it is the simplest fix. Instead of letting Python attempt the impossible division, your function will check for zero and return a message.
- In calculator.py, find the divide function. It currently looks like this:
def divide(x, y):
return x / y
- Replace the entire divide function with this version that checks for zero:
def divide(x, y):
# Check if dividing by zero before attempting division
if y == 0:
return "Cannot divide by zero"
return x / y
What does this code do?
Before performing the division, the function checks whether y is zero. If it is, the function returns a friendly message string instead of attempting x / y (which would crash). If y is not zero, division proceeds normally.
- Save calculator.py and run it to test the fix:
python calculator.py
- Enter 5 for the first number, 0 for the second, and choose option 4 (Divide).
You should see Cannot divide by zero printed instead of a crash.
Still seeing ZeroDivisionError?
Make sure you saved calculator.py before running it. Check that the if y == 0: line is indented inside the function (one level of indentation).
Why is my divide function still crashing?
Now for the bigger fix. You need to handle the case where someone types a word instead of a number. Python's try/except lets you attempt something risky and catch the error if it fails, instead of crashing.
- In calculator.py, find the first number input section. It currently looks like this:
first_input = input("Enter first number: ")
num1 = float(first_input)
- Replace those two lines with this code that wraps the conversion in a try/except block:
first_input = input("Enter first number: ")
# Try to convert the input to a number
try:
num1 = float(first_input)
except ValueError:
print("Invalid input. Please enter a number.")
exit()
What does try/except do?
The try block attempts to run float(first_input). If it succeeds, the program continues normally. If it raises a ValueError (because the input is not a valid number), Python jumps to the except block instead of crashing.
The exit() call stops the program cleanly after printing the message. In the next step, you will replace this with a loop that asks again.
- Now find the second number input section. It currently looks like this:
second_input = input("Enter second number: ")
num2 = float(second_input)
- Replace those two lines with the same try/except pattern for the second number:
second_input = input("Enter second number: ")
# Try to convert the second input to a number
try:
num2 = float(second_input)
except ValueError:
print("Invalid input. Please enter a number.")
exit()
- Finally, find the else clause at the bottom of your if/elif block. It currently looks like this:
else:
print("Invalid choice.")
- Replace it with a more helpful message and a clean exit:
else:
print("Invalid choice. Please enter 1, 2, 3, or 4.")
exit()
- Save calculator.py.
Seeing IndentationError?
Make sure the try keyword starts at the same indentation level as the first_input line above it (no extra spaces). The num1 = float(first_input) line must be indented one level inside the try: block.
Help me fix my indentation in the try/except block
Test your fixes
Time to prove that both crashes are gone. Before you run the program, what do you think will happen if you type "hello" now?
- Run the program:
python calculator.py
- Type hello when it asks for the first number.
You see Invalid input. Please enter a number. printed and the program exits cleanly. No crash.
- Run it one more time:
python calculator.py
- Enter 10 for the first number, 0 for the second, and choose option 4 (Divide).
You see Cannot divide by zero printed in the result. No crash.
✔️ Awesome, I've got everything!
Great. Double check you have saved calculator.py.
ⓧ I'd like to double check the full code
Your calculator.py should have these sections in this order. Scroll up and confirm each one is present:
- The add, subtract, multiply, and divide functions at the top (divide now has the if y == 0 check).
- The first input with try/except ValueError around float(first_input).
- The second input with try/except ValueError around float(second_input).
- The operation menu and if/elif/else block (the else now prints a more helpful message and calls exit()).
- The final print(f"\n{num1} {symbol} {num2} = {result}") line at the bottom.
Your calculator now handles bad input gracefully. Next up, you will make it loop so you can keep calculating without restarting the program every time.
Loop Until Quit
Your calculator handles bad input gracefully and never crashes. But there is still one annoying limitation.
Every time you finish a calculation, the program exits. You have to run python calculator.py again just to do another one. A while True loop solves this by repeating the main logic until the user decides to stop.
In this step, get ready to:
- Wrap your calculator logic in a loop that keeps running.
- Add a quit command so the user can exit cleanly.
- Perform multiple calculations in a row without restarting.
Replace your main code with a loop
Right now, the code below your four functions runs once from top to bottom and exits. You will replace all of it with a loop that repeats until the user types "quit".
- In calculator.py, select everything below the divide function (starting from first_input = input("Enter first number: ") all the way to the last line).
- Delete the selected code.
- Add the following code in its place, starting on the blank line after the divide function:
# Welcome message
print("Python Calculator")
print("Type 'quit' to exit.")
print()
while True:
# Ask for the first number
first_input = input("Enter first number (or 'quit' to exit): ")
# Check if user wants to quit
if first_input.lower() == "quit":
print("Goodbye!")
break
# Convert input to a number, loop back on error
try:
num1 = float(first_input)
except ValueError:
print("Invalid input. Please enter a number.\n")
continue
What does this code do?
This introduces three new ideas that work together to keep the calculator running.
- while True: creates an infinite loop. Everything indented beneath it repeats forever until something tells it to stop.
- break is how you stop the loop. When the user types "quit", break exits the loop and the program ends.
- continue skips the rest of the current loop iteration and jumps back to the top. If the input is invalid, continue sends the user straight back to "Enter first number" without running the rest of the code.
- Save calculator.py and run it in the terminal by typing:
python calculator.py
- Type quit when prompted for the first number.
You should see "Goodbye!" printed and the program exits cleanly.
Program not stopping?
Make sure first_input.lower() == "quit" uses .lower() so it catches "Quit", "QUIT", and "quit" equally. Also check that break is indented inside the if block.
If the program hangs and you cannot type anything, press Ctrl+C in the terminal to force-stop it.
Help me debug my while loop
Complete the loop body
The quit and first-number logic works. Now add the rest of the calculator inside the loop so the user can pick an operation and see the result before the loop asks for a new calculation.
- Directly below the continue line you just wrote (still inside the while True block), add the second number input and operation menu:
# Get the second number
second_input = input("Enter second number: ")
# Convert second input, loop back on error
try:
num2 = float(second_input)
except ValueError:
print("Invalid input. Please enter a number.\n")
continue
# Display the operation menu
print("\nChoose an operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
choice = input("Enter choice (1/2/3/4): ")
What changed from the old code?
This code looks familiar because it is almost identical to what you had before. The two key differences are the indentation (everything is inside the while True block now) and continue replacing exit().
Previously, exit() killed the whole program on bad input. Now continue just skips back to the top of the loop, giving the user another chance.
- Directly below the choice = input("Enter choice (1/2/3/4): ") line, add the operation logic and result output:
# Call the matching function based on user's choice
if choice == "1":
result = add(num1, num2)
symbol = "+"
elif choice == "2":
result = subtract(num1, num2)
symbol = "-"
elif choice == "3":
result = multiply(num1, num2)
symbol = "*"
elif choice == "4":
result = divide(num1, num2)
symbol = "/"
else:
print("Invalid choice. Please enter 1, 2, 3, or 4.\n")
continue
# Display the result
print(f"\n{num1} {symbol} {num2} = {result}\n")
Why does the else block use continue now?
In your old code, an invalid choice called exit() and ended the program. Now continue skips back to the top of the loop and asks for a new first number. The user gets to try again instead of losing their session.
The \n at the end of each print statement adds a blank line before the next prompt. This keeps the output readable when calculations repeat in a loop.
- Save calculator.py.
✔️ Awesome, I've got everything!
Great. Double check that your file is saved before moving on.
ⓧ I'd like to double check the full code
Your calculator.py should now contain three sections in this order:
- The four function definitions (add, subtract, multiply, divide) at the top, unchanged.
- The welcome message and while True: loop opening, with the quit check and first number input (chunk 1 above).
- The second number input, operation menu, choice handling with if/elif/else, and the result print (chunks 2 and 3 above).
Scroll up and confirm each section is present. Every line from the while True: onward must be indented by 4 spaces (one level inside the loop).
Test your looping calculator
Your calculator should now keep running after each calculation. Before you test, think about what you expect to happen when you do three calculations and then type "quit".
- Run the program:
python calculator.py
- Perform a calculation: enter 10 and 5 as your numbers, then choose option 1 (Add).
- Confirm the result prints and the program immediately asks for a new first number.
- Do two more calculations using different operations.
- Type quit when asked for the first number.
You should see "Goodbye!" printed and the program exits. All three calculations ran without you restarting the program once.
Program exiting after one calculation?
This means your code is not inside the while True block. Check that every line from first_input = input(...) through the final print is indented by exactly 4 spaces. Python uses indentation to know what belongs inside the loop.
Also make sure there is no exit() left in your code from the previous step. Those should all be replaced with continue.
Help me fix my calculator loop
Your calculator now runs as long as you want. Next up, you will extend it with a Secret Mission feature that remembers every calculation you have done.
Secret mission
Add Calculation History
Your calculator forgets everything the moment it prints a result. What if it could remember every calculation you have done in a session? In this secret mission, you will add a history feature that stores past results and displays them on command.
Clean Up Your Resources
Clean Up Your Resources
Decide whether to keep your resources running, pause them to come back later, or delete them entirely. This project runs entirely locally, so there are no ongoing costs.
Resources you used:
- calculator.py file.
- Python 3.14.6 installation.
- VS Code with the Microsoft Python extension.
Keep everything running
No action needed. Choose this if you plan to keep learning Python or start another project soon.
- Python and VS Code stay installed on your machine, ready for your next project.
- Your calculator.py file stays wherever you saved it.
Pause - I'll come back to this later
There are no running processes or cloud resources to pause. Everything in this project is local and idle.
- Python and VS Code do not run in the background, so no action is needed.
- Your files remain on disk until you delete them manually.
Delete - I don't want to use this again
Remove all project resources and tools. Only do this if you are sure you will not use Python or VS Code again.
- Delete calculator.py by right-clicking the file in File Explorer and selecting Delete. Alternatively, run this in the terminal from the folder where the file is saved:
- macOS/Linux: rm calculator.py
- Windows: del calculator.py
To uninstall Python:
- Open Windows Settings.
- Select Apps, then Installed apps.
- Search for Python 3.14, click the three-dot menu next to it, and select Uninstall.
To uninstall VS Code:
- In the same Installed apps list, search for Visual Studio Code.
- Click the three-dot menu and select Uninstall.
Nice Work!
Nice Work!
You just built a fully interactive command-line calculator in Python from scratch. It takes input, does math, handles mistakes gracefully, and loops until you decide to stop.
Here's what you learned:
- Built a complete interactive program using Python functions for each math operation, taking user input and printing results back immediately.
- Added error handling with try/except so bad input and divide-by-zero produce friendly messages instead of crashes.
- Used a while loop to keep the calculator running for unlimited calculations until the user types quit.
- Secret Mission: Stored calculation history in a list and displayed past results on command using a for loop.
Ready to quiz yourself?