Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python TypeError must be str not int [duplicate]

Tags:

I am having trouble with the following piece of code:

    if verb == "stoke":

        if items["furnace"] >= 1:
            print("going to stoke the furnace")

            if items["coal"] >= 1:
                print("successful!")
                temperature += 250 
                print("the furnace is now " + (temperature) + "degrees!")
                           ^this line is where the issue is occuring
            else:
                print("you can't")

        else:
            print("you have nothing to stoke")

The resulting error comes up as the following:

    Traceback(most recent call last):
       File "C:\Users\User\Documents\Python\smelting game 0.3.1 build 
       incomplete.py"
     , line 227, in <module>
         print("the furnace is now " + (temperature) + "degrees!")
    TypeError: must be str, not int

I am unsure what the problem is as i have changed the name from temp to temperature and added the brackets around temperature but still the error occurs.

like image 535
Eps12 Gaming Avatar asked Jul 05 '17 03:07

Eps12 Gaming


1 Answers

print("the furnace is now " + str(temperature) + "degrees!")

cast it to str

like image 112
PYA Avatar answered Sep 28 '22 03:09

PYA