hello i m new to python and i m making a mud game so i m stuck at a certain point where i have to create a character and following is my code. as i need to give 2 option to the player with the description and then player will select one of the given choices. help me with the code in 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()
You have some syntax errors and you need to pass a string as a function argument.
From what I can tell you want to first select a character and then change the output based on your selection.
Your code is almost working you just need to fix the syntax errors and save the selection in a variable, to be able to pass it to the next function.
The characters should be converted to strings, so you can check if they are equal to the passed argument
chosencharacter
. You also should use anelif
instead of a secondif
because, otherwise the secondif
would get evaluated (toFalse
) even if the first one isTrue
.