17/01/2024, 02:25 COMP 3006 Homework 1 Functional programming and OOP intro General Homework Guidelines: Homework must be submitted in a .py file. Please do not submit .ipynb files. Homework should
not use packages or functions that have not yet been discussed in class. Use comments to explain what your code is doing. Use a consistent coding style. Use descriptive variable names. Test your code regularly using a variety of different inputs. - Every function must include a docstring for documentation (see: https://realpython.com/documenting-python-code/). This docstring should include: mediatb.blob.core.windows.net/media//65a6d985ae3e820bbf3182f5/questions/assignment1-1_170543359... 1 or 2 lines describing what the function does - Args: input parameters, their types and what they are for - Returns: return data type and what it is All tests of your functions should be commented out in your final submission or encolosed with an if name == '____main__ codeblock. I - All functions should use return statements to return a value, rather than printing some value, unless the instructions specifically say to print. # Question 1: # Create a function, called student_id_numbers, that takes a list of student names # and generates an automatic student id number. The function must be able to handle # collisions using dictionaries. A collision will happen when students have the same # last name. The function must return the dictionary or dictionaries containing the # students and their student id numbers. # Note: using defaultdict might be helpful but not required. Having some good music # while you code this might be helpful but also not required. # You will also need to write a second function, called retrieve student_number that # will take a student's name and will return their student id number. This function # will need to handle misspelled names. #Question 2: # In France there is a child's marching song called "Un Kilometre a Pied" which # translates to One Kilometer On Foot. The lyrics are: # One kilometer on foot wears out, wears out, # One kilometer on foot wears out your shoes for good. #... # Two kilometers on foot wears out, wears out, # Two kilometers on foot wears out your shoes for good. # The lyrics repeat to infinity (or rather until the kids get tired of singing). # Create a function, called un_kilometre_a_pied, which takes no parameters and prints # the lyrics of the song to the console. The function must make use of a generator to # write the lyrics of the song until the user decides to stop. The generator you use must # be able to produce a value that increses to infinity. You must make sure that your code # doesn't get caught in an infinite loop that is difficult to exit, I recommend having # the necessary logic to allow the user to exit whenever they get tired of the song. ### ### ### We wish to compare and store data on various types of shelters for when we go backpacking ### ### #Question 3: # Create a class, called Tent, that contains the following attributes (in the order https://mediatb.blob.core.windows.net/media//65a6d985ae3e820bbf3182f5/questions/assignment1-1_1705433595922.py 1/3 17/01/2024, 02:25 given): # num_occupants (int) # material (str) #setup_time (int, number of minutes) mediatb.blob.core.windows.net/media//65a6d985ae3e820bbf3182f5/questions/assignment1-1_170543359... # sqft (float) # vestibule (bool, True if tent has a vestibule) #weight (float) # structure_poles (bool, True if tent has structural poles. Should have a default value of True) # seasons (int, 3 or 4. Should have a default value of 3) #The class should also have the following methods: # str # repr # _lt_ (this should use the num_occupants and sqft attributes to determine if one tent is # less than another tent) # is_better (a tent is considered better if and only if its weight and setup_time is less than # another tent whilst having equal or better season rating) #Question 4: # We wish to compare and store data on various types of shelters for when we go backpacking. Create a class, called Hammock, that contains the following attributes (in the order given): # num_occupants (int) # material (str) # setup_time (int, number of minutes) #weight (float) # length (int, length of hammock in feet. Should have a default value of 11) # seasons (int, 3 or 4. Should have a default value of 3) #The class should also have the following methods: # str # repr # _lt_ (this should use the weight and setup_time attributes to determine if one hammock is # less than another hammock) # is better (a tent is considered better if and only if its weight and setup_time is less than # another tent whilst having equal or better season rating) #Question 5: # Create a class, called Tarp, that contains the following attributes (in the order given): # num_occupants (int) # material (str) # setup_time (int, number of minutes) # sqft (float) #weight (float) #seasons (int, 3 or 4. Should have a default value of 3) #The class should also have the following methods: # str # repr _lt____ (this should use the num_occupants and sqft attributes to determine if one tent # is # less than another tent) # is_better (a tent is considered better if and only if its weight and setup_time is less than # another tent whilst having equal or better season rating) https://mediatb.blob.core.windows.net/media//65a6d985ae3e820bbf3182f5/questions/assignment1-1_1705433595922.py 2/3 17/01/2024, 02:25 #Question 6: # There is lots of repeated code above, let's create a parent class for Tent, Hammock and Tarp # called Shelter. The Shelter class should have a constructor that takes over all of the # attributes that are common for Tent, Hammock and Tarp. The Shelter class should also include # the is better method. You will also need to create a new method called mediatb.blob.core.windows.net/media//65a6d985ae3e820bbf3182f5/questions/assignment1-1_170543359... total_sleeping_spots # which will add up the total number of sleeping spots available from a non-determined number # of Shelters being passed into the method. # Rewrite the Tent, Hammock and Tarp classes taking into account the changes brought on by using # the Shelter parent class. https://mediatb.blob.core.windows.net/media//65a6d985ae3e820bbf3182f5/questions/assignment1-1_1705433595922.py 3/3