lundi 19 octobre 2020

I'm trying to stop this if-elif from asking further questions after the correct response is provided

The code below asks you 4 yes/no questions, but you're only supposed to say yes to one of them. They go in the order as it shows below, but I want this to stop asking the questions as soon as the user says yes.

Example: You answer "yes" to the first question "Do you want to listen to hip-hop? (yes/no)" then it shouldn't ask the other 3 questions. If you say no to the first two questions and yes to the third it should not ask the fourth.

Are there any commands that I don't know? I tried using "else" instead of "elif" for the last command, but that didn't do what I wanted. Thanks!

print("We have the following genres, choose one: hip-hop, alt-rock, indie rock, electronic")
hiphop = input("Do you want to listen to hip-hop? (yes/no)")
altrock = input("Do you want to listen to alt-rock? (yes/no)")
indierock = input("Do you want to listen to indie-rock? (yes/no)")
electronic = input("Do you want to listen to electronic? (yes/no)")
hhsongs = ("Jay-Z - Feelin' It", "Notorious B.I.G. - Big Poppa", "Ice Cube - Today Was a Good Day", "Eazy-E - Boyz-n-the-Hood", "Dr. Dre - Nuthin' but a G Thang")
arsongs = ("Radiohead - Karma Police", "Beck - Loser", "Cage the Elephant - Ain't No Rest for the Wicked", "The Killers - Mr. Brightside")
irsongs = ("The Strokes - Hard to Explain", "The Spinto Band - Oh Mandy", "The Pixies - Here Comes Your Man", "Vampire Weekend - A Punk")
esongs = ("Daft Punk - One More Time", "Justice - Genesis", "Deadmau5 - Animal", "Flyring Lotus - GNG BNG")
if hiphop == "yes":
    import random
    print("Suggested: " + random.choice(hhsongs))
elif altrock == "alt-rock":
    import random
    print("Suggested: " + random.choice(arsongs))
elif indierock == "indie rock":
    import random
    print("Suggested: " + random.choice(irsongs))
elif electronic:
    import random
    print("Suggested: " + random.choice(esongs))



Aucun commentaire:

Enregistrer un commentaire