[Python] Python executing print statements inside false ifs

Discussão em 'Python' iniciado por Stack, Setembro 16, 2024.

  1. Stack

    Stack Membro Participativo

    salt = "Salt and Vinegar"
    bland = "Saltenes"
    sweet = "Chocolate"
    spicy = "Takis"
    sour = "Sour Patch Kids"
    q1 = print(input("Do you want a bland or flavorful snack? "))
    q2 = print(input("Do you want a sweeter or saltier snack? "))
    q3 = print(input("Would you like a sour snack or not? "))
    q4 = print(input("Would you like a spicy snack or not? "))
    rec = ""

    print(input("Do you want a bland or flavorful snack? "))
    if q1 == "Bland":
    rec = bland
    elif q1 == "Flavorful":
    print(input("Do you want a sweeter or saltier snack? "))
    if q2 == "Sweeter":
    print(input("Would you like a sour snack or not? "))
    if q3 == "Sour":
    rec = sour
    elif q3 == "Not":
    rec = sweet
    elif q2 == "Saltier":
    print(input("Would you like a spicy snack or not? "))
    if q4 == "Spicy":
    rec = spicy
    elif q4 =="Not":
    rec = salt

    print("We recommend " + rec + " as your snack!")


    My code looks like this. I'm having issues with it running, for example, print(input("Do you want a sweeter or saltier snack? ")) even when the persons input was Bland, and, thus, shouldn't run the rest of the program.

    I already made each question it's own variable and had all my final answers be variables. I'm relatively sure that the, for example, q1 == "Bland" using a string shouldn't ruin my code but it's very possible I'm wrong. I'm new to coding.

    Continue reading...

Compartilhe esta Página