Most popular tags

302 questions

410 answers

70 comments

310 users

Most active Members
this week:

    How can i put multiple answers to an if statement?

    0 votes

    i want my if statement to have multiple answers without using an or statement, how is this possible??

     

    y_n=input("Do you want to play a game?")
     

    if y_n == "y" "yes" "yeah" "n" "no" "nah":

     

     

    asked Nov 4, 2016 in Python by 14goldinga (710 points)

    1 Answer

    0 votes
     
    Best answer
    You can use ...
    If x in ("cat", "dog", "pig")

    Will match if x has any of the values cat, dog or pig.
    answered Nov 13, 2016 by smartin (16,520 points)
    selected Dec 2, 2016 by 14goldinga
    Welcome to Selby Computing Q&A, where you can ask questions and receive answers from other students in Computer Science.
    ...