THis may have been asked before so apologies but i literally just started 'learning' Python 3 two days ago.
As part of an exercise you build a very simple calculator but all it can do is one operation at a time (i.e. result = variable 1 +-* variable 2 ) how do i get the result to take into account my operator variable?
num1 = float(input("Enter a Number Greater than 1: "))
oper = input("Choose a math Operation (+, -, /, *) :")
num2 = float(input("Enter another Number: "))
result = float(num1) oper float(num2)
print(result)
I am told mapping the operator to a function like lambda, but how do i do this exactly ? The gist is i want to just be able to use a divide, add, multiply and minus operator between the Input statements. i wrote
num1 = float(input("Enter a Number Greater than 1: ")) + = lambda num1,num2 : num1 + num2 * = lambda num1,num2 : num1 * num2 - = lambda num1,num2 : num1 - num2 / = lambda num1,num2 : num1 / num2 num2 = float(input("Enter another Number: ")) result = float(num1) oper float(num2) print(result)