โ† Back to Python Course
๐Ÿ› ๏ธ Functionsยท30 minยทIntermediate๐Ÿ† Project
๐Ÿงฎ

Mini-Project: Calculator App

Build a working calculator!

Use functions with parameters and returns to build a calculator that can add, subtract, multiply, and divide!

๐Ÿ“–

What we are learning

Time to build a real calculator! You will create functions for addition, subtraction, multiplication, and division. Each function takes two numbers as parameters and returns the result. Then you will build a menu so the user can choose an operation!

๐Ÿ’ก Think of it like this:

Think of this project like building a mini robot calculator. Each math operation is a separate "skill" (function) the robot has. The user picks which skill to use, gives two numbers, and the robot does the rest!

๐ŸŒŸ

Why it matters

This project shows how functions with parameters and returns work together. It is a mini version of the calculator app on your phone โ€” built from scratch with your own code!

Where you see this in real life:

  • โœ“Calculator apps on phones and computers
  • โœ“Spreadsheet formulas that do calculations
  • โœ“Shopping apps that calculate totals and discounts
๐ŸŽฏ

By the end, you can:

  • 1.Write functions for each math operation
  • 2.Use parameters to pass in numbers
  • 3.Use return to send back results
  • 4.Build an interactive menu with input()
๐Ÿ”ค

New words

functionparameterreturninputfloat
๐Ÿ
What operations should a calculator have? Write down all the math operations you can think of!
๐Ÿค“

Fun Fact!

The first mechanical calculator was built in 1642 by Blaise Pascal. It could only add and subtract. Your Python calculator can do much more!

๐Ÿงฎ Build a Calculator App!

Time to build a real calculator! You will create functions for each math operation, each taking two numbers as parameters and returning the result. Then you will build an interactive menu!

๐Ÿ—๏ธ Step 1: Math Functions

First, create a function for each operation. Each takes two numbers and returns the result.

๐ŸStep 1: Create math functions
main.py
โ— Output
Click โ–ถ Run to see the output!

๐Ÿ—๏ธ Step 2: The Full Calculator

Now add a menu so the user can choose an operation and enter numbers!

๐ŸStep 2: The complete calculator!
main.py
โ— Output
Click โ–ถ Run to see the output!

๐Ÿš€ Challenge: Add More Features!

  • ๐ŸŒŸ Add a power function (num1 to the power of num2)
  • ๐ŸŒŸ Add a modulo (remainder) function
  • ๐ŸŒŸ Handle division by zero (show an error message)
  • ๐ŸŒŸ Let the user do multiple calculations in a loop
๐ŸYour turn โ€” add more features!
main.py
โ— Output
Click โ–ถ Run to see the output!
๐Ÿ
Amazing! You built a working calculator! ๐ŸŽ‰ You used functions, parameters, returns, if/elif/else, and input all together!
๐Ÿง 

Quick Quiz!

+15 XP

Why do we use float() when getting numbers from input()?

๐Ÿ
Finished the lesson? Click the button to mark it complete and earn XP!