Mar-09-2018, 09:58 AM
The following program works:
#!/usr/bin/env python3 #MovieList.py def displayMenu(): print("COMMAND MENU") print("list - List all movies") print("add - Add a movie") print("del - Delete a movie") print("exit - Exit program") def list(movieList): i = 1 for movie in movieList: print(str(i) + ". " + movie) i += 1 print() def add(movieList): movie = input("Name: ") movieList.append(movie) print(movie + " was added.\n") def delete(movieList): number = int(input("Movie Number: ")) if number < 1 or number > len(movieList): print("Invalid movie number.\n") else: movie = movieList.pop(number-1)#movie numbers on the console may start #with 1, but the indexes for the movies in the movieList start with 0. #Therefore, (number-1) causes the correct index of the movie that we #want to delete to be referenced. print(movie + " was deleted successfully.\n") def main(): movieList = ["Monty Python and the Holy Grail", "Uncle Bazerko's Violent Adventure", "The Expendables", "Duke Nukem: Fate of Humanity"] displayMenu() while True: command = input("Enter command: ") if command.lower() == "list": list(movieList) elif command.lower() == "add": add(movieList) elif command.lower() == "del": delete(movieList) elif command.lower() == "exit": break else: print("Not a valid command. Please try again.\n") print("Bye!") if __name__ == "__main__": main()However, I don't quite understand line 41. While what is true? Is the condition simply set to false once we have officially exited the program on line 54?