Python TypeError 必须是 str 而不是 int [英] Python TypeError must be str not int

查看:82
本文介绍了Python TypeError 必须是 str 而不是 int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用以下代码时遇到问题:

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")

产生的错误如下:

    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

我不确定问题是什么,因为我已将名称从 temp 更改为温度并在温度周围添加了括号,但仍然发生错误.

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.

推荐答案

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

将其转换为 str

这篇关于Python TypeError 必须是 str 而不是 int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆