[Python] It works for long hair but not for short hair

Discussão em 'Python' iniciado por Stack, Setembro 10, 2025.

  1. Stack

    Stack Membro Participativo

    I'm sort of new to programming but also not. Anyway, I'm trying to build a basic choice, text-based game in python and there's something wrong with my code, but I can't figure out what. Essentially, I'm asking the user if they have long or short hair using if-else statements based on the user input.

    It works for long hair but when I type in short, the program tells me I have long hair and that's incorrect. Yet, I can't figure out what I've done wrong with my code.

    Here's the code if the image isn't clear or doesn't show:

    if(character == "girl"):
    print("You identify as a girl.")
    print("Do you have long or short hair?")

    hair = input("> ")

    if(hair == "long") or ("long hair"):
    print("You are a girl with long hair.")
    print("Are you ready to get a date? Yes or no?")

    answer = input("> ")

    elif(hair == "short") or ("short hair"):
    print("You are a girl with short hair.")
    print("Are you ready to get a date? Yes or no?")


    Yes, there is an else statement that occurs after the elif, so I know that's not the problem (but maybe it is?). Does anyone know what's wrong with the code or if there's a better way to do this?

    I want the prompts of the story to be based upon the input from the user. Right here, I've given the user two choices, long or long hair and short or short hair. Depending on the user input, the screen is either supposed to print, "You are a girl/boy/nonbinary person with long hair" or "You are a girl/boy/nonbinary person with short hair" (boy and nonbinary person paths not shown).

    But it only prints the long hair option even if you type short or short hair.

    Continue reading...

Compartilhe esta Página