Skip to content Skip to sidebar Skip to footer

Typeerror: Cannot Concatenate 'str' And 'int' Objects Can Someone Please Help A Newbie With Their Code?

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('How many days?') loc

Solution 1:

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

Solution 2:

the problem is that days is a string.

when you do

return140 * days

it actually multiples your string to 140. so if days == "5" you will have "555555555555555555..." (140 characters)

you want to operate with integers so do days = int(day) instead

Post a Comment for "Typeerror: Cannot Concatenate 'str' And 'int' Objects Can Someone Please Help A Newbie With Their Code?"