Python 涉及列表的列表和循环出错

Python 涉及列表的列表和循环出错,python,Python,这就是我目前掌握的代码。我有一个问题,当我选择一个选项,做了说的选项,然后再选择另一个,它不让你做。我不确定我的for x in range()中的错误是什么,但韦小宝(在线python程序)将其作为错误运行。我的清单也不起作用。我可以添加一个节目,但它不是保存 提前感谢您的帮助。您似乎是python新手。您的代码有很多语法和语法错误。只要看一下代码,试着找出错误所在 choice = int() show_list= [] def main(): print("1. Li

这就是我目前掌握的代码。我有一个问题,当我选择一个选项,做了说的选项,然后再选择另一个,它不让你做。我不确定我的for x in range()中的错误是什么,但韦小宝(在线python程序)将其作为错误运行。我的清单也不起作用。我可以添加一个节目,但它不是保存


提前感谢您的帮助。

您似乎是python新手。您的代码有很多语法和语法错误。只要看一下代码,试着找出错误所在

choice = int()

show_list= []

def main():
    print("1. List all TV Shows")
    print("2. Add a TV Show")
    print("3. Delete a TV Show")
    print("4. Exit")
    choice = input("Please enter a number: ")
    choice = int(choice)

    if choice == 1:
      print(show_list) 
      main()       
    
    elif choice == 2:
      add_shows = int(input("Enter number of TV shows to add: "))
    
      while True:2
         for x in range(add_shows): #error
            show = [input(("Please enter your TV Show: ").strip())]
            show.append(show_list)
        else:
            break
    main()
                         
    elif choice == 3:
      remove_shows = int(input("Enter number of TV shows to delete: "))
    
     while True:
          for x in range(add_shows): #error
              show = [input(("Please enter your TV Show: ").strip())]
              show.append(show_list)
          else:
              break
      main()
    
    elif choice == 4:
     print("Goodbye")
如果您有任何问题,请随时在评论中提问


附言:不要为落选而烦恼。发生。

错误消息是什么?您的函数
main()
似乎一直在自己调用。我认为你应该使用一个循环。请正确地识别你的代码,我们甚至不知道什么是<代码>:破解< /代码>与你在<代码>主< <代码>的中间调用<代码>主代码(<)>代码>非常感谢。我明白我做错了什么。我对python非常陌生,在google上搜索就找不到所需的帮助。我最初使用的是spyder,它没有告诉我错误是什么。所以我不知道。我真的很感激!不过我很好奇。为什么是choice-1Look,我们在实际使用(获取输入)之前使用choice变量(在while语句中)。所以,我们需要在第一个while语句中预先使用一些值,对吗?所以-1只是为了确保选项中的值不是4,这样循环就不会提前终止。你可以在那里输入任何值,除了4。我现在明白了。谢谢你的解释
show_list= []
choice = -1

while choice != 4:
    print("1. List all TV Shows")
    print("2. Add a TV Show")
    print("3. Delete a TV Show")
    print("4. Exit")
    choice = input("Please enter a number: ")
    choice = int(choice)

    if choice == 1:
      print(show_list)   
    
    elif choice == 2:
      add_shows = int(input("Enter number of TV shows to add: "))
    
      for x in range(add_shows):
          show = input(("Please enter your TV Show: ").strip())
          show_list.append(show)
                         
    elif choice == 3:
      remove_shows = int(input("Enter number of TV shows to delete: "))
    
      for x in range(remove_shows):
         show = input(("Please enter your TV Show: ").strip())
         show_list.remove(show)
    
    elif choice == 4:
     print("Goodbye")