Python: cannot concatenate ‘str’ and ‘int’ objects error

I’m trying to create a little program that lets the user to buy stuff from the shop or money buy working at a job.

Code:

#Info before user starts

print "Enter job, shop, or exit"
print ""

#--------------------------------------------------------------------------------------------
#Variabls

name = raw_input("What is your name?")
ask = raw_input("Where do you want to go:")
currency = 20

#--------------------------------------------------------------------------------------------
#Functions

def job():
  print "hello"

def shop():
  print "Hello " + name + ", what would you like? You have $" + currency

#-------------------------------------------------------------------------------------------
#Body

while (ask != "job") and (ask != "shop") and (ask != "exit"):
  print "That is not an option. Please choose job, shop, or exit"
  ask = raw_input("Where do you want to go:")

if(ask == "job"):
  job()
elif (ask == "shop"):
  shop()

The programs asks the user’s name and asks where he would like to go. For the function shop, the program should print: “Hi [User’s name], What would you like? You have $20”. When I run it, it shows up this error:

Traceback (most recent call last):
  File "python", line 30, in <module>
  File "python", line 18, in shop
TypeError: cannot concatenate 'str' and 'int' objects

Could anyone explain what is happening?

Leave a Comment