On this page

Guided Exercise: Build an Interactive Calculator

Enrico Hochkoeppler Profile

By Enrico Hochkoeppler

Web Developer & TutoriaLibre Founder

Objective​

This challenge consolidates all concepts from Module 1: variables, data types, input, output, operators, and expressions. You will build a small but complete program that interacts with the user, processes data, and produces meaningful results.

Requirements​

Your calculator must:

  1. Ask the user for two numbers
  2. Ask the user which operation to perform
  3. Compute the result using the correct operator
  4. Display the result clearly
  5. Handle at least the four basic operations: addition, subtraction, multiplication, and division

Each step must use the concepts learned in previous lessons.

Step‑by‑Step Guidance​

1. Read Two Numbers from the User​

Use input() to collect values and convert them to numbers.


x = float(input("Enter the first number: "))

y = float(input("Enter the second number: "))

2. Ask for the Operation​

Prompt the user to choose an operator.


operation = input("Choose an operation (+, -, *, /): ")

3. Compute the Result​

Use expressions and operators to compute the correct value.


if operation == "+":

    result = x + y

elif operation == "-":

    result = x - y

elif operation == "*":

    result = x * y

elif operation == "/":

    result = x / y

4. Display the Output​

Use print() to show the final result.


print("Result:", result)

Full Example Solution​

This is one possible implementation. Your own version may differ as long as it satisfies the requirements.


x = float(input("Enter the first number: "))

y = float(input("Enter the second number: "))



operation = input("Choose an operation (+, -, *, /): ")



if operation == "+":

    result = x + y

elif operation == "-":

    result = x - y

elif operation == "*":

    result = x * y

elif operation == "/":

    result = x / y



print("Result:", result)

What You Should Learn from This Challenge​

Completing this exercise demonstrates that you can:

These skills form the foundation for all future modules.

Found this helpful? Share the knowledge...

... or support this project to keep it alive!

Buy Me a Coffee

Previous

Operators and Expressions

Next

Control Flow