Recap - Simple Calculator
Part of the Fundamentals section of Coddy's Python journey — lesson 22 of 77.
Challenge
BeginnerYou are given a code which gets as input two numbers n1 and n2 and a character op.
Note: we will learn in next lessons how to get input from the user, currently just don't touch the three first lines.
The possible values for op are '+', '-', '/' and '*'
Your task is to set the variable result based on the conditions:
- if
opis'+', setresultwithn1 + n2. - if
opis'-', setresultwithn1 - n2. - if
opis'/', setresultwithn1 / n2. - if
opis'*', setresultwithn1 * n2.
Try it yourself
n1 = int(input()) # Don't change this line
n2 = int(input()) # Don't change this line
op = input() # Don't change this line
result = 0
# Don't change the line below
print(f"result = {result}")All lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 48Loops
For LoopWhile LoopBreakContinueRecap - FactorialThe Range FunctionNested LoopRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators9Functions
Declare a FunctionArgumentsReturnRecap - Sigma FunctionRecap - Validation FunctionDefault Values12Iterating Over Sequences
Iterating Over ElementsThe Enumerate FunctionIterating Over Strings Part 1Iterating Over Strings Part 2