python - 为什么会发生此错误?TypeError:只能将str(不是“int”)连接到str
问题描述
这是我的 Python 代码,我想知道错误的原因
TypeError:只能将str(不是“int”)连接到str
正在发生,以及如何解决它:
import random
print("Welcome to the Text adventures Game\nIn this Game you will go on an amazing adventure.")
print("Following are the rules:\n1.You can type the directions you want to go in.\n2. There will be certain items that you will encounter. You can type grab to take it or leave to leave it\n3.In the starting, we will randomly give you 3 values. It is your choice to assign them to your qualites.\nYour Qualities are:\n1.Intelligence\n3.Attack\n4.Defence\n These Qualities will help you further in the game")
print("With these, You are all set to play the game.")
Name=input(str("Please Enter Your Name: "))
a=input("Hi "+Name+", Ready To Play The Game?: ")
Intelligence=0
Attack=0
Defence=0
if a=="yes"or a=="y":
value1=random.randint(0,100)
choice1=input("Your Value is: \n"+value1+ "\nYou would like to make it your Intelligence,Attack Or Defence level? ")
解决方案
您正在尝试添加int
到string
尝试这个
if a=="yes"or a=="y":
value1=random.randint(0,100)
choice1=input("Your Value is: \n"+str(value1)+ "\nYou would like to make it your Intelligence,Attack Or Defence level? ")
推荐阅读
- http - 是否可以在浏览器中调用解析?
- google-classroom - 调用课堂 PHP API 方法时出错:courses.courseWork.list
- c# - sftp文件上传C#
- pyspark - Spark shell 打开时出现异常:无法从 URL [文件:log4j 属性] 读取配置文件
- wordpress - 如何阻止重力表单提交保存到本地数据库?
- java - 如何使用 Selenium/Java 在前钩子中动态获取正确的页面类?
- sqlite - 在内存中使用 xUnit/EFCore/sqlite 时测试之间的数据溢出
- ansible - 使用 if 条件将 True 或 False 分配给 Ansible 中的gather_facts 不起作用
- spartacus-storefront - 更改特定组件的响应媒体的媒体类型
- c# - 如何从 HttpRequestMessage.Properties 迁移到 HttpRequestMessage.Options