Search code examples
pythonraw-input

TypeError: can't multiply sequence by non-int of type 'float' python 2.7


Hi I'm a 11 year old who has taken up python as a hobby. I'm trying to make a mass converter as a first project. But for some reason I've been getting this error: TypeError: can't multiply sequence by non-int of type 'float'

Here is my code:

    print "please enter the amount of kilograms you want to convert",
    kilo = raw_input() 
    pounds = 2.20462

    print kilo * pounds

Solution

  • raw_input returns a string, you're basically doing this:

    print "1234" * 2.20462
    

    You need to convert the input to a number:

    kilo = float(raw_input())
    pounds = 2.20462
    
    print kilo * pounds
    

     

    The error message is somewhat confusing because you can multiply a string (or any sequence) by an integer:

    print "abc" * 3   # prints "abcabcabc"