[Python] How to keep a '+' function like a math operator when it is contained in a variable...

Discussão em 'Python' iniciado por Stack, Julho 17, 2025.

  1. Stack

    Stack Membro Participativo

    sum1=0
    while True:

    input1 = (input('Please enter a number '))
    input2 = (input('Please input operator '))
    if not(input1=='end')or not(input2=='end'):
    input1=float(input1)
    #I need it to perform a math operation
    #example: some variable (num) then a variable (math operator) and a second variable (num)
    sum1= (sum1 input2 input3) # does not work

    print(sum1)


    I want the operator to work but I don't know the necessary data type/built-in function. I tried using f strings and then converting back to float but it sticks it together example: str 5.0 + 6.0 cannot be converted to float.

    Continue reading...

Compartilhe esta Página