Continue After Certain Input
尝试使用while循环并获得相同的错误
1 2 3 4 5 6 7 8 | 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 |
这个脚本是为了询问用户他们感兴趣的电视节目。如果不是(此时),Seinfeld,它应该打印"Show X not Available"。 我有这个工作,但我希望脚本然后重新开始并要求输入另一个节目。 有什么建议?
1 2 3 4 5 6 7 | show_name = str(input("Please Enter Show Name:")).upper() if show_name in ['SEINFELD', 'JERRY SEINFELD', 'THE SEINFELD SHOW', 'JERRY']: seinfeld_keywords = (str(input("Please Enter Seinfeld Keywords:"))).upper() else: print("Sorry, %s Is Not Currently Available. Please Check Back Soon!" %show_name) continue |
你需要一个while循环。 我还稍微重构了你的代码,使它更清晰一些:
1 2 3 4 5 | 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() |