你好,我是新来的python和我正在做一个泥游戏,所以我在某个点卡住了,我必须创建一个字符,下面是我的代码。因为我需要给予2个选项的描述,然后玩家将选择给定的选择之一。帮助我在python的代码。
def selectcharacter():
character = ""
while character != "Red pirate" and character != "dreed prince":
character = input("which character you want to choose? (Red pirate or Dreed prince ):")
return character
def checkcharacter(chosencharacter):
if (chosencharacter == Red pirate):
print("the ability of the character is to fight close range battles and has 125 health and 50 armor!"),
if (chosencharacter == Dreed prince):
print("the ability of the character is to fight long range battles and has 100 health and 25 armor!")
else:
print("no character selected.please select the character!")
checkcharacter()
selectcharacter()
1条答案
按热度按时间lsmepo6l1#
您有一些语法错误,需要将字符串作为函数参数传递。
从我可以告诉你想要首先选择一个字符,然后改变输出的基础上,您的选择。
您的代码几乎可以正常工作了,您只需要修复语法错误并将选择保存在一个变量中,以便能够将其传递给下一个函数。
这些字符应该被转换成字符串,这样你就可以检查它们是否等于传递的参数
chosencharacter
。你还应该使用elif
而不是第二个if
,因为,否则第二个if
将被求值(为False
),即使第一个是True
。