Python编程,游戏语法错误 #制作一个可变的名称来识别玩家的名字 name=input(“你好,你叫什么名字?”) #打印他们的名字 打印(“你好”,姓名) #控制台询问玩家是否想玩游戏,如果选择“是”,则继续,否则说“好的,再见”(在底部!!) 打印(“你想听故事吗?”,姓名) 选择=输入(“是,否?”) 如果选项==(“是”或“是”或“是”或“是”): 打印(“确定”,姓名,”,收听) 印刷品(“曾经有一座古老的房子,在一座山的山顶上,高得很,高得很,在云层之上”) housename=input(“你想叫房子什么?”) 印刷品(“旧的,”,housename,“曾经是一位老太太的。你决定去“housename”,你在路上遇到一个鬼。你看到你旁边有各种各样的武器,一把斧头,一把剑和一把弓。”) #询问玩家是否需要斧头、剑或弓 choice3=输入(“您选择斧头、剑还是弓?”) #如果选择“bow”,则继续执行此代码 如果选项3==(“弓”或“弓”或“弓”或“弓”): 打印(“你装备了劣质的弓,弓感觉随时都可能折断。”) #将敌人健康设置为10 enemyhealth=int(10) #做一个while循环以保持战斗进行,而不是1次。 当enemyhealth>=1时: 打印(“拍摄!”) bowattack=输入(“键入攻击以发射箭头!”) 如果攻击==(“攻击”): 随机输入 #损伤发生器随机化器 损害=[“1”、“2”、“3”、“4”] 损伤2=int(随机选择(损伤)) enemyhealth=enemyhealth-损害2 打印(“幽灵受到了一些伤害。敌人的健康:”,敌人的健康) 其他: 打印(“您确定键入了快照吗?”) #如果敌人的生命值低于1印,你就杀死了鬼魂,奖励系统**这就是我遇到的问题** 如果enemyhealth

Python编程,游戏语法错误 #制作一个可变的名称来识别玩家的名字 name=input(“你好,你叫什么名字?”) #打印他们的名字 打印(“你好”,姓名) #控制台询问玩家是否想玩游戏,如果选择“是”,则继续,否则说“好的,再见”(在底部!!) 打印(“你想听故事吗?”,姓名) 选择=输入(“是,否?”) 如果选项==(“是”或“是”或“是”或“是”): 打印(“确定”,姓名,”,收听) 印刷品(“曾经有一座古老的房子,在一座山的山顶上,高得很,高得很,在云层之上”) housename=input(“你想叫房子什么?”) 印刷品(“旧的,”,housename,“曾经是一位老太太的。你决定去“housename”,你在路上遇到一个鬼。你看到你旁边有各种各样的武器,一把斧头,一把剑和一把弓。”) #询问玩家是否需要斧头、剑或弓 choice3=输入(“您选择斧头、剑还是弓?”) #如果选择“bow”,则继续执行此代码 如果选项3==(“弓”或“弓”或“弓”或“弓”): 打印(“你装备了劣质的弓,弓感觉随时都可能折断。”) #将敌人健康设置为10 enemyhealth=int(10) #做一个while循环以保持战斗进行,而不是1次。 当enemyhealth>=1时: 打印(“拍摄!”) bowattack=输入(“键入攻击以发射箭头!”) 如果攻击==(“攻击”): 随机输入 #损伤发生器随机化器 损害=[“1”、“2”、“3”、“4”] 损伤2=int(随机选择(损伤)) enemyhealth=enemyhealth-损害2 打印(“幽灵受到了一些伤害。敌人的健康:”,敌人的健康) 其他: 打印(“您确定键入了快照吗?”) #如果敌人的生命值低于1印,你就杀死了鬼魂,奖励系统**这就是我遇到的问题** 如果enemyhealth,python,syntax,Python,Syntax,上一行缺少右括号: #makes a varible called name to identify the players name name=input("Hello person, Whats your name?") #prints their name print("Hello", name) #console asks the player if they want to play the game, if choice is "yes" then continue, else

上一行缺少右括号:

#makes a varible called name to identify the players name
name=input("Hello person, Whats your name?")
#prints their name
print("Hello", name)
#console asks the player if they want to play the game, if choice is "yes" then continue,   else say "ok bye bye" (at the bottom!!)
print("Do you want to hear a story?", name)
choice=input("Yes, No?")
if choice==("yes" or "yes " or "Yes" or "Yes "):
    print("Ok", name,", listen up")    
    print("There was once an old, old house at the top of a hill Sooooo high it was above the clouds")
    housename=input("What do you want to call the house?")
    print("The old,",housename,"was once owned by an old lady. You decide to go up to   the", housename, ",you encounter a ghost in your path. You see a varitety of weapons beside  you, an axe, sword and a bow.")
#asks the player if they want an axe sword or bow    
    choice3=input("Do you choose the axe, sword or bow?")
#if the choice is "bow" then proceed with this code    
    if choice3==("bow" or "Bow" or "bow " or "Bow "):
        print("You equip the shoddy Bow, The bow feels as if it could snap any second.")
#sets the enemyshealth as 10
        enemyhealth=int(10)
#makes a while loop to keep the battle going instead of 1 time.
        while enemyhealth >= 1:
            print("Take a shot!")
            bowattack=input("Type attack to fire an arrow!")
            if bowattack==("attack"):
                import random
#randomiser for damage generator
                damage = ["1", "2", "3", "4"]
                damage2 = int(random.choice(damage))
                enemyhealth = enemyhealth - damage2
                print("The ghost took some damage. Enemys health:", enemyhealth)

            else:
                print("Are you sure you typed shoot?")
#if the enemys health gets below 1 print you killed the ghost, reward system! **this is what im having trouble with!!**
    if enemyhealth <= 1:
        print("You killed the Ghost!!")
        print("You vanquished the ghost, you now collect a new weapon!")
#confirms the reward, either gives the player a shiny bow or a double shot bow.
        import random
        reward = ["Shiny bow", "Doubleshot bow"]
#randomiser for either reward
        reward2 =(random.choice(reward)
#prints what weapon the player got
#THIS IS THE PROBLEM, ON THIS LINE
        print("You got a:", reward2)



    #pointless easteregg :D        
    elif choice==("maybe"):
        print("You found an easter egg, congrats. PS this does nothing")
#if the player typed anything other than yes say ok bye bye.
else:
    print("Ok, bye bye", name)
应该是:

reward2 =(random.choice(reward)

前一行中缺少右括号:

#makes a varible called name to identify the players name
name=input("Hello person, Whats your name?")
#prints their name
print("Hello", name)
#console asks the player if they want to play the game, if choice is "yes" then continue,   else say "ok bye bye" (at the bottom!!)
print("Do you want to hear a story?", name)
choice=input("Yes, No?")
if choice==("yes" or "yes " or "Yes" or "Yes "):
    print("Ok", name,", listen up")    
    print("There was once an old, old house at the top of a hill Sooooo high it was above the clouds")
    housename=input("What do you want to call the house?")
    print("The old,",housename,"was once owned by an old lady. You decide to go up to   the", housename, ",you encounter a ghost in your path. You see a varitety of weapons beside  you, an axe, sword and a bow.")
#asks the player if they want an axe sword or bow    
    choice3=input("Do you choose the axe, sword or bow?")
#if the choice is "bow" then proceed with this code    
    if choice3==("bow" or "Bow" or "bow " or "Bow "):
        print("You equip the shoddy Bow, The bow feels as if it could snap any second.")
#sets the enemyshealth as 10
        enemyhealth=int(10)
#makes a while loop to keep the battle going instead of 1 time.
        while enemyhealth >= 1:
            print("Take a shot!")
            bowattack=input("Type attack to fire an arrow!")
            if bowattack==("attack"):
                import random
#randomiser for damage generator
                damage = ["1", "2", "3", "4"]
                damage2 = int(random.choice(damage))
                enemyhealth = enemyhealth - damage2
                print("The ghost took some damage. Enemys health:", enemyhealth)

            else:
                print("Are you sure you typed shoot?")
#if the enemys health gets below 1 print you killed the ghost, reward system! **this is what im having trouble with!!**
    if enemyhealth <= 1:
        print("You killed the Ghost!!")
        print("You vanquished the ghost, you now collect a new weapon!")
#confirms the reward, either gives the player a shiny bow or a double shot bow.
        import random
        reward = ["Shiny bow", "Doubleshot bow"]
#randomiser for either reward
        reward2 =(random.choice(reward)
#prints what weapon the player got
#THIS IS THE PROBLEM, ON THIS LINE
        print("You got a:", reward2)



    #pointless easteregg :D        
    elif choice==("maybe"):
        print("You found an easter egg, congrats. PS this does nothing")
#if the player typed anything other than yes say ok bye bye.
else:
    print("Ok, bye bye", name)
应该是:

reward2 =(random.choice(reward)

另外,如果选项==('yes'或'yes'或'yes'或'yes'):行将不起作用

试试这个:

if choice.strip().lower()=“是”:
#随便
strip
将删除空白
lower
将以小写形式显示字符串


同样的情况也发生在
选项3

中,如果选项==('yes'或'yes'或'yes'或'yes'或'yes'):也不起作用

试试这个:

if choice.strip().lower()=“是”:
#随便
strip
将删除空白
lower
将以小写形式显示字符串


同样的情况也发生在
选项3

对不起,你说的是哪一行。我对python简直是个迷:(对不起,你说的是哪一行。我对python简直是个迷:(一次又一次地问同样的问题。也许我们应该安装一个机器人,检测标题中的“语法错误”,并回答“你在前一行中缺少一个右括号。”:-)同样的问题一遍又一遍。也许我们应该安装一个机器人,检测标题中的“语法错误”,并回答“上一行中缺少一个右括号。”:-)谢谢帮助:)欢迎。。。另一件事,您不需要在任何时候调用随机函数时
导入random
。在代码顶部导入它。感谢您的帮助:)欢迎。。。另一件事,您不需要在任何时候调用随机函数时
导入random
。在代码顶部导入它。