[Python] How to conver raw_input() from a text using int() in python

Discussão em 'Python' iniciado por Stack, Abril 15, 2025.

  1. Stack

    Stack Membro Participativo

    i am learning to code in python. I am learning how to use numbers as string data from raw_input and convert these numbers to integers then use them to do number manipulations such as multiplications. Below my code is the error i am getting. Any light on this will be very welcomed. Thanks

    python

    num = raw_input("what is your favourite number?")
    num= int(num) #convert num from text into a number using int() and double it.
    print("Double my favourite number is ") +(num*2)


    python This is the error i am getting

    python

    TypeError: cannot concatenate 'str' and 'int' objects on line 3 in main.py

    python

    Continue reading...

Compartilhe esta Página