Project design
- Python course
- Beginner
- Lesson 19/116
- 6 min
Design the calculator skeleton.
Project: Calculator
In this 5-lesson project you'll build a calculator. Each lesson adds one piece, and by the final lesson you'll have a complete app.
You'll use what you learned before:
- variable assignment
- output with print
- int and float types
You'll also learn the function (def), if and try/except structures. Ready? Let's start.
The calculator flow
The calculator works in four steps:
- Input: two numbers are taken.
- Operation: an operator is chosen (+, -, *, /).
- Compute: the result is found based on the operator.
- Output: the result is printed.
In the first lesson we'll just define two numbers and print them. The next lessons add functions and error handling.
Practice Define two numbers and print them
First piece of the calculator: assign 10 to a, assign 5 to b. Then print both with print(a, b).
Starter code
# Calculator - define two numbersSample solution
a = 10
b = 5
print(a, b)Expected output
10 5
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does a calculator need first to work?
- Two numbers and an operation Correct answer
- A database
- A class
- A file
Explanation: A calculator takes two numbers and performs an operation.
2 Assign 10 to the first number
a = ____
print(a)
a = 10
print(a)
Explanation: a = 10 assigns an integer value.
3 Match each calculator step to its description
| Term | Meaning |
|---|---|
Input |
Two numbers are taken |
Operation |
Operator is chosen |
Compute |
Result is found |
Output |
Result is printed |