Question

In: Computer Science

Modify the Movie List 2D program -Modify the program so it contains four columns: name, year,...

Modify the Movie List 2D program

-Modify the program so it contains four columns: name, year, price and rating (G,PG,R…)

-Enhance the program so it provides a find by rating function that lists all of the movies that have a specified rating

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()

Solutions

Expert Solution

Program:

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: ")
    price=int(input("Price: ")) #taking price
    rating=float(input("Rating (1 - 10):")) #taking rating
    movie = []
    movie.append(name)
    movie.append(year)
    movie.append(price) #adding price to movie list
    movie.append(rating) #adding rating to movie list
    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 find_by_rating(movie_list,rating): #find function
    if len(movie_list)==0:
        print('Add movies to find')
        return
    else:
        l=[] #list to store the movies
        for i in movie_list: #loop
            if i[3]==rating:
                l.append(i[0])
        if len(l)==0:
            print("No movies are present with given rating")
        else:
            print("movies are:")
            for i in l: #loop
                print(i) #printing the movies



def display_menu():
    print("COMMAND MENU")
    print("list - List all movies")
    print("add - Add a movie")
    print("del - Delete a movie")
    print("find - find by rating")
    print("exit - Exit program")
    print()

movie_list = [["Monty Python and the Holy Grail", 1975,200,5],["On the Waterfront", 1954,400,6],["Cat on a Hot Tin Roof", 1958,300,8]]
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 == "find": #added find command
        rating=int(input("Enter rating: ")) #taking rating
        find_by_rating(movie_list,rating) #calling find by rating function
    elif command == "exit":
        break
    else:
        print("Not a valid command. Please try again.\n")
    print("Bye!")
Program Screenshot :

Output:

I have commented the code where I changed..

Hope you understand...

If you have any doubts comment below..plss dont dislike....


Related Solutions

In Python Modify the program so it contains four columns: name, year, price and rating (G,PG,R…)...
In Python Modify the program so it contains four columns: name, year, price and rating (G,PG,R…) Enhance the program so it provides a find by rating function that lists all of the movies that have a specified rating 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...
"4. (Modify) Modify Program 7.14 so that the user inputs the initial set of numbers when...
"4. (Modify) Modify Program 7.14 so that the user inputs the initial set of numbers when the program runs. Have the program request the number of initial numbers to be entered." //C++ Program 7.14 as follows #include #include #include #include using namespace std; int main() { const int NUMELS = 4; int n[] = {136, 122, 109, 146}; int i; vector partnums(n, n + NUMELS); cout << "\nThe vector initially has the size of " << int(partnums.size()) << ",\n and...
Change program linkedListClass to the linked list for student items (a student item contains id, name...
Change program linkedListClass to the linked list for student items (a student item contains id, name and score, where the id is used as key) and test it in the main method. You can define a student item using a class of student. given the following codes; import java.util.*; public class linkedListClass {    public Node header;    public linkedListClass()    {        header = null;    }    public final Node Search(int key)    {        Node...
PYTHON Modify the program in section Ask the user for a first name and a last...
PYTHON Modify the program in section Ask the user for a first name and a last name of several people.  Use a loop to ask for user input of each person’s first and last names  Each time through the loop, use a dictionary to store the first and last names of that person  Add that dictionary to a list to create a master list of the names  Example dictionary: aDict = { "fname":"Douglas", "name":"Lee" } ...
Modify the AlienDirection program from this chapter so that the image is not allowed to move...
Modify the AlienDirection program from this chapter so that the image is not allowed to move out of the visible area of the window. Ignore any key that would allow this to happen. *Ask if you have any questions about the assignment I will try to clarify Textbook - JAVA FOUNDATIONS: INTRODUCTION TO PROGRAM DESIGN AND DATA STRUCTURES 5TH EDITION Starter Code Provided : import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.KeyEvent; import javafx.scene.paint.Color; import javafx.stage.Stage;...
In c++, modify this program so that you allow the user to enter the min and...
In c++, modify this program so that you allow the user to enter the min and maximum values (In this case they cannot be defined as constants, why?). // This program demonstrates random numbers. #include <iostream> #include <cstdlib> // rand and srand #include <ctime> // For the time function using namespace std; int main() { // Get the system time. unsigned seed = time(0); // Seed the random number generator. srand(seed); // Display three random numbers. cout << rand() <<...
Modify this program so that it takes in input from a TEXT FILE and outputs the...
Modify this program so that it takes in input from a TEXT FILE and outputs the results in a seperate OUTPUT FILE. (C programming)! Program works just need to modify it to take in input from a text file and output the results in an output file. ________________________________________________________________________________________________ #include <stdio.h> #include <string.h> // Maximum string size #define MAX_SIZE 1000 int countOccurrences(char * str, char * toSearch); int main() { char str[MAX_SIZE]; char toSearch[MAX_SIZE]; char ch; int count,len,a[26]={0},p[MAX_SIZE]={0},temp; int i,j; //Take...
Modify the program so that after it reads the line typed on the keyboard, it replaces...
Modify the program so that after it reads the line typed on the keyboard, it replaces the ‘\n’ character with a NUL character. Now you have stored the input as a C-style string, and you can echo it with: Explain what you did. #include <unistd.h> #include <string.h> int main(void) { char aString[200]; char *stringPtr = aString; write(STDOUT_FILENO, "Enter a text string: ", strlen("Enter a text string: ")); // prompt user read(STDIN_FILENO, stringPtr, 1); // get first character while (*stringPtr !=...
[PYTHON] Modify the examaverages.py program included with this assignment so it will also compute the overall...
[PYTHON] Modify the examaverages.py program included with this assignment so it will also compute the overall average test grade. E.g if there are 3 test each student must take and the user enters the following set of test scores for the two students…: 30, 40, 50 for the first student 50, 60, 70 for the second student …then program will print the average for each student (i.e. 40 for the first student and 60 for the second student – the...
Modify the GreenvilleRevenue program so that it uses the Contestant class and performs the following tasks:...
Modify the GreenvilleRevenue program so that it uses the Contestant class and performs the following tasks: The program prompts the user for the number of contestants in this year’s competition; the number must be between 0 and 30. The program continues to prompt the user until a valid value is entered. The expected revenue is calculated and displayed. The revenue is $25 per contestant. For example if there were 3 contestants, the expected revenue would be displayed as: Revenue expected...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT