【发布时间】:2020-01-30 14:23:49
【问题描述】:
这是我的 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? ")
【问题讨论】:
-
将您的整数变量类型转换为 str。像这样
str(value1)
标签: python