栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python TypeError must be str not int

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python TypeError must be str not int

发现论坛里没有相关解释,翻译了stackoverflow上的回答,留以备用

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:UsersUserdocumentsPythonsmelting game 0.3.1 build 
       incomplete.py"
     , line 227, in 
         print("the furnace is now " + (temperature) + "degrees!")
    TypeError: must be str, not int

回答:

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

cast it to str
使用str转换int格式到str

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/767437.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号