首页 > 解决方案 > 为什么会发生此错误?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? ")

标签: python

解决方案


您正在尝试添加intstring

尝试这个

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

推荐阅读