TypeError: cannot concatenate 'str' and 'int' objects Can someone please help a newbie with their code?

后端 未结 2 2060
我在风中等你
我在风中等你 2021-01-28 08:32

Any help is appreciated, also any big flaws or something you see in the way im formatting or something basic, please point it out. Thanks!

day = raw_input(\"         


        
2条回答
  •  感动是毒
    2021-01-28 09:15

    First thing to understand is that raw_input returns a string, so there's no need to cast the result to a string afterwards.

    What you want (I think) is to cast day to an int, so you need to change the top part.

    day = raw_input("How many days?")
    location = raw_input("Where to?")
    days = int(day)
    spendingMoney = 100
    

    In your original code, days was a string, and so you were trying to add a string to and integer (which raised the error).

    Multiplying a string by an integer is perfectly valid, as it simply repeats the original string several times over.

    print 'foobar' * 5
    # foobarfoobarfoobarfoobarfoobar
    

提交回复
热议问题