[Python] entering int or float using input()

Discussão em 'Python' iniciado por Stack, Outubro 6, 2024.

  1. Stack

    Stack Membro Participativo

    I need to enter different values to input(), sometimes integer sometime float. My code is

    number1 = input()
    number2 = input()
    Formula = (number1 + 20) * (10 + number2)


    I know that input() returns a string which is why I need to convert the numbers to float or int. But how can I enter a float or integer without using number1 = int(input()) for example? because my input values are both floats and integers so I need a code that accepts both somehow.

    Continue reading...

Compartilhe esta Página