problem in character creation for mud game in python

54 Views Asked by At

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()
1

There are 1 best solutions below

0
On

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.

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"):  # should be string
        print("the ability of the character is to fight close range battles and has 125 health and 50 armor!"),
    elif (chosencharacter == "Dreed prince"):  # should be string
        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!")


selected_character = selectcharacter()
checkcharacter(selected_character)

The characters should be converted to strings, so you can check if they are equal to the passed argument chosencharacter. You also should use an elif instead of a second if because, otherwise the second if would get evaluated (to False) even if the first one is True.