I went through a lesson of creating a simple calculator using Python, and I'm trying to simplify it. The issue is as follows: I know that it is possible to parse a string (number) into a float using "float()", but I'm trying to parse a addition/subtraction/multiplication/division sign from a string into a float or integer or any other format that would perform the action. Here's a sample of what I'm trying to do:
while True:
user_input = input("""
quit - exit program
add - addition
sub - subtraction
mul - multiplication
div - division
Please choose function:""")
actions = ("+-*/")
user_input_1 = float(input("first number:"))
user_input_2 = float(input("second number:"))
operation = user_input_1 float(action) user_input_2
if user_input == "add":
action = actions[0]
answer = operation
print (answer)
If the user_input is "add" user_input_1 is "5" user_input_2 is "7" then the print(answer) should result in 12
This is just the first part of the code, and I'm getting a syntax error. The issue is most likely the inability to parse the addition sign using "float()". Is there another way of parsing the signs?