Continue After Certain Input

时间:2015-07-28 23:43:24

标签: python loops

Tried using a while loop and get the same error

ValuesController.getState();

This script is meant to ask the user what TV show they are interested in. If it is not (at this point), Seinfeld, it should print "Show X is Not Available." I've got that working, but I'd like the script to then start over and ask for another show to be input. Any suggestions?

show_name = str(input("Please Enter Show Name: ")).upper()

if show_name in ['SEINFELD', 'JERRY SEINFELD', 'THE SEINFELD SHOW', 'JERRY']:    
    while True:
        seinfeld_keywords = (str(input("Please Enter Seinfeld Keywords: "))).upper()
    if not seinfeld_keywords: 
        print("Sorry, %s Is Not Currently Available.  Please Check Back Soon!" %show_name)
        continue

1 个答案:

答案 0 :(得分:1)

你需要一个while循环。我还稍微重构了你的代码,使它更清晰:

show_name = input("Please Enter Show Name: ").upper()
while show_name not in ('SEINFELD', 'JERRY SEINFELD', 'THE SEINFELD SHOW', 'JERRY'):
    print("Sorry, {} Is Not Currently Available.  Please Check Back Soon!".format(show_name))
    show_name = input("Please Enter Show Name: ").upper()
seinfeld_keywords = input("Please Enter Seinfeld Keywords: ").upper()