CodeBlanks Logo Icon CodeBlanks

Project design

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:

  1. Input: two numbers are taken.
  2. Operation: an operator is chosen (+, -, *, /).
  3. Compute: the result is found based on the operator.
  4. 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

main.py
# Calculator - define two numbers

Sample solution

main.py
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

Question
a = ____
print(a)
Answer
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

All lessons in Beginner