Just moving my comment to an answer. There are extremely few cases where eval
should be used, and this is not one of them. It adds unnecessary security risks to your script, and while this particular use case is quite simple, you're better off just not getting into the habit of using it.
I would suggest mapping the operators to the actual methods that are run, and calling the method (eg. 5 + 10
is actually int(5).__add__(10)
). See here for more information on these.
operators = {
'+': '__add__',
'-': '__sub__',
'*': '__mul__',
'/': '__div__',
}
First = input("First Number: ")
Operator = input("Operator: ")
Second = input("Second Number: ")
Sum = getattr(float(First), operators[Operator])(float(Second))
print(Sum)