Please correct my code as I\'m getting the error shown in the picture Question:
ID: 3904534 • Letter: P
Question
Please correct my code as I'm getting the error shown in the picture
Question: Video Store [2 points] Recall the movie database example given in class. In this question, you are to complete two functions in the following cell using the table movies from videostore. db For the function allMovies() , return a list of all movie records where each record is in the form of tuple. For example, if table movies of videostore.db contains only two records, say (101, "Casablanca', 'drama romance', PG') (102, Back to the Future', 'comedy adventure', "PG) then the function should return the list (101 Casablanca' 'drama romance' PG'), (102, Back to the Future' comedy adventure', 'PG')] The function addMovie(movieid, title, genre, rating) takes four inputs to add a new movie record to the database. For simplicity, you may assume that all inputs to addMovies(..) are appropriate In [65] def allMovies() dbsqlite3.connect('videostore.db') cursor = db . cursor() sql- "SELECT * FROM MOVIES"! cursor.execute (sql) resultscursor.fetchallo) for row in results: movieidrow[e] title - row[1] genre row[2] rating row[3] print("novieid-Xs,title-%s,genre-M , rating-Xs" % (movieid, title, genre, rating) ) db.close() def addMovie(movieid, title, genre, rating): db sqlite3 . connect('videostore . db') cursor-db.cursor) sql"INSERT INTO MOVIE (MOVIEID, TITLE, VALUES GENRE, (%d', RATING) '%s', %s', %s')" % (movieid, title, genre, rating) cursor.execute (sql) db.commit() db.close()Explanation / Answer
Make sure that your database contains the movies table as the error message says that no such table exists.
Also, in the addMovie() function, in the INSERT statement, change MOVIE to MOVIES.
If the movies table does not exist in your database, then execute the given statement below before to create the table.
cursor.execute('''
CREATE TABLE movies(movieid INTEGER PRIMARY KEY, titleTEXT,
genreTEXT, ratingTEXT)
''')
Also, try to use ''' (three quotes for your query) like shown above for your query in the allMovies() function.
Everything else looks fine in your code.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.