Menu
CoddyTech

Recap - Simple Calculator

Part of the Fundamentals section of Coddy's Python journey. Lesson 22 of 77.

challenge icon

Challenge

Beginner

You are given a code which gets as input two numbers n1 and n2 and a character op.

Note: n1, n2 and op are already set for you, with different values in each test case. Don't set them yourself, just use them.

 

The possible values for op are '+', '-', '/' and '*'

Your task is to set the variable result based on the conditions:

  • if op is '+', set result with n1 + n2.
  • if op is '-', set result with n1 - n2.
  • if op is '/', set result with n1 / n2.
  • if op is '*', set result with n1 * n2.

Try it yourself

# n1, n2 and op are already set for you
result = 0

# Don't change the line below
print(f"result = {result}")

All lessons in Fundamentals

Practice on your own: Online Python compiler