即使答案不正确,for 循环也不会循环

The for loop doesn't loop even when the answer is not right

The problem may be somewhere in the end,the for loop stops and the input is asked

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":
        band=input("Enter the name of the band")
        for word in range(3):
            if band=="Queen":
                print("You win a concert ticket!")
                break
    enter = input('Enter 1 - recommendation, 2 - draw, off - exit')  ```
           

for 循环实际上是在循环,它只是做任何事情,除非答案是正确的。你想要:

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') 

只需将第 11 行与第 12 行交换,以便输入调用在循环中。

我认为使用:

会略有改进
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')