lab01 : Python Classes

num ready? description assigned due
lab01 true Python Classes Fri 01/12 11:00AM Mon 01/22 11:59PM

In this lab, you’ll have the opportunity to practice:

Note: In general, it is always important to work on labs and reading early so you can gain the proper context and utilize our office hours to seek assistance / ask clarifying questions during the week before the deadline, if needed!

It is a good idea to read up on some tools we’ll use in this lab before you get started, specifically Chapter 1.4.2.1 (String Formatting) and 1.4.6 - 1.4.6.1 (Object Oriented Programming).

The main idea for this lab is to write a program that will organize Movies into a Movie list. The program should have the ability to add / remove / search for movies.

Instructions

We recommend that you organize your lab work for this lab in its own directory, e.g., lab01. This way all files for a lab are located in a single folder. Also, this will be easy to import various files into your code using the import / from technique shown in lecture.

You will need to create two files (note that the file names are case-sensitive when we import them in Python!):

There will be no starter code for this assignment, but rather the class descriptions and required methods are defined in the specification below.

Movie.py class

The Movie.py file will contain the definition of a Movie.

We will define the Movie attributes as follows:

You will write a constructor that allows the user to construct a Movie object by passing in values for all of the fields. Your constructor should set these attributes with the value None by default.

In addition to your constructor, your class definition should also support “setter” methods that can update the state of the Movie objects:

Each Movie object should be able to call a method toString() that you will implement, which returns a str with all the movie attributes EXACTLY as shown (i.e., the string should contain all attributes in the following EXACT format "Title" (GENRE) - YEAR):

movie1 = Movie("About time", "Drama", 2013)
print(movie1.toString())
print() # separate two movies with a newline
movie2 = Movie("eternal sunshine of the spotless mind", "Sci-Fi", 2004)
print(movie2.toString())

Output:

"About Time" (DRAMA) - 2013
"Eternal Sunshine Of The Spotless Mind" (SCI-FI) - 2004

IMPORTANT: The .toString() return value in the example above does not contain a newline character (\n) at the end.

MovieList.py

The MovieList.py file will contain the definition of a single MovieList object.

An MovieList object will contain a dictionary structure where the keys of the dictionary will be a str type representing a Movie’s genre (all upper-case characters).

The dictionary value will be a list of Movie objects that the MovieList contains. Note that the order of the Movies in the list is based on when the Movie object was inserted into the dictionary structure (most recent Movie inserted will be at the end of the list).

Your code should support the following constructor and methods:

Submission

Once you’re done with writing your class definition, submit your Movie.py, and MovieList.py to the Lab01 assignment on Gradescope. There will be various unit tests Gradescope will run to ensure your code is working correctly based on the specifications given in this lab.

If the tests don’t pass, you may get some error message that may or may not be obvious at this point. Don’t worry - if the tests didn’t pass, take a minute to think about what may have caused the error. Check the Troubleshooting guide below. If your tests didn’t pass and you’re still not sure why you’re getting the error, feel free to ask your TAs or Learning Assistants.

Troubleshooting

ModuleNotFoundError: No module named ...

Check that you named your file EXACTLY as was specified - remember that Python is case-sensitive.


NoneType has no attribute ...

Remember that before you can use .title() or .upper() in your constructor, you need to verify that the parameter is a string instead of None. Use the if/else branches to differentiate between these cases.


The autograder failed to execute correctly. Please ensure that your submission is valid. Contact your course staff for help in debugging this issue. Make sure to include a link to this page so that they can help you most effectively.

This may be because your code contains print() statements when submitting to Gradescope. Print statements sometimes confuses the autograder resulting in this message. In general, lab submissions do not require any print statements (though it may be helpful to use when debugging). If you see this error, try removing any print statements in your code and see if that resolves your issue.


EOF error

If you are getting an EOF error, check that you are not using input() anywhere in your code. Parameters are passed directly into the function call, so there is no need for user input.