In: Computer Science
In Python
def list(movie_list):
if len(movie_list) == 0:
print("There are no movies in the list.\n")
return
else:
i = 1
for row in movie_list:
print(str(i) + ". " + row[0] + " (" + str(row[1]) + ")")
i += 1
print()
def add(movie_list):
name = input("Name: ")
year = input("Year: ")
movie = []
movie.append(name)
movie.append(year)
movie_list.append(movie)
print(movie[0] + " was added.\n")
def delete(movie_list):
number = int(input("Number: "))
if number < 1 or number > len(movie_list):
print("Invalid movie number.\n")
else:
movie = movie_list.pop(number-1)
print(movie[0] + " was deleted.\n")
def display_menu():
print("COMMAND MENU")
print("list - List all movies")
print("add - Add a movie")
print("del - Delete a movie")
print("exit - Exit program")
print()
def main():
movie_list = [["Monty Python and the Holy Grail", 1975],
["On the Waterfront", 1954],
["Cat on a Hot Tin Roof", 1958]]
display_menu()
while True:
command = input("Command: ")
if command == "list":
list(movie_list)
elif command == "add":
add(movie_list)
elif command == "del":
delete(movie_list)
elif command == "exit":
break
else:
print("Not a valid command. Please try again.\n")
print("Bye!")
if __name__ == "__main__":
main()
I just don't get how to modify it. Any help will be appreciated!
Please find the answer below.Given code is in python,
Hence indentation is very important . Make sure you are
referring screenshot to match indentation after coping the
code.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
def list(movie_list):
if len(movie_list) == 0:
print("There are no movies in the list.\n")
return
else:
i = 1
for row in movie_list:
print(str(i) + ". " + row[0] + " (" + str(row[1]) + ") Rate :
"+str(row[3])+" @ $"+str(row[2]))
i += 1
print()
def add(movie_list):
name = input("Name : ")
year = input("Year : ")
price = input("Price : ")
rating = input("Rating : ")
movie = []
movie.append(name)
movie.append(year)
movie.append(price)
movie.append(rating)
movie_list.append(movie)
print(movie[0] + " was added.\n")
def delete(movie_list):
number = int(input("Number: "))
if number < 1 or number > len(movie_list):
print("Invalid movie number.\n")
else:
movie = movie_list.pop(number-1)
print(movie[0] + " was deleted.\n")
def display_menu():
print("COMMAND MENU")
print("list - List all movies")
print("add - Add a movie")
print("del - Delete a movie")
print("exit - Exit program")
print()
def main():
movie_list = [["Monty Python and the Holy Grail",
1975,190.90,"G"],
["On the Waterfront", 1954,3190.90,"A"],
["Cat on a Hot Tin Roof", 1958,1490.90,"PG"]]
display_menu()
while True:
command = input("Command: ")
if command == "list":
list(movie_list)
elif command == "add":
add(movie_list)
elif command == "del":
delete(movie_list)
elif command == "exit":
break
else:
print("Not a valid command. Please try again.\n")
print("Bye!")
if __name__ == "__main__":
main()