[Solved] The for loop doesn’t loop even when the answer is not right [closed]


The for loop actually does loop, it just does do anything unless the answer is correct. you want:

while enter!="off":
    if enter == "1":
        prefer= input("enter your preference")
        if prefer =="sports":
            print("Hardcore Sports Podcast")
            enter = input('Enter 1 - recommendation, 2 - draw, off - exit')
        else:
            print("Kanye West's new album")
            enter = input('Enter 1 - recommendation, 2 - draw, off - exit')
    if enter=="2":
        for word in range(3): #swapped this line
            band=input("Enter the name of the band") #with this line
            if band=="Queen":
                print("You win a concert ticket!")
                break

    enter = input('Enter 1 - recommendation, 2 - draw, off - exit') 

Just swap line 11 with line 12 so that the input call is in the loop.

I think a slight improvement would be to use:

while enter!="off":
    if enter == "1":
        prefer= input("enter your preference")
        print("Hardcore Sports Podcast") if prefer =="sports" else print("Kanye West's new album")
    if enter=="2":
        for _ in range(3):
            band = input("Enter the name of the band")
            if band == "Queen":
                print("You win a concert ticket!")
                break
    enter = input('Enter 1 - recommendation, 2 - draw, off - exit')  

2

solved The for loop doesn’t loop even when the answer is not right [closed]