You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import operator
ops = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.truediv, # Use truediv for floating-point division
'**': operator.pow
}
while True:
try:
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
op = input("Enter the operation (+, -, *, /, **): ")
if op in ops:
result = ops[op](num1, num2)
print(f"Result: {result}")
break # Exit the loop if the operation is successful
else:
print("Invalid operation. Please choose from +, -, *, /, **.")
except ValueError:
print("Invalid input. Please enter numbers only.") #1