Joy and Beauty of Data, Second Practicum – March 30, 2017
Total Page:16
File Type:pdf, Size:1020Kb
Joy and Beauty of Data, Second Practicum – March 30, 2017 Name _______________________________________________________________ Question One. 25 points. Supply the missing function so that when this code runs: stranger_things = {} stranger_things["The Vanishing of Will Byers"] = "The Duffer Brothers" stranger_things["The Weirdo on Maple Street"] = "The Duffer Brothers" stranger_things["Holly, Jolly"] = "Shawn Levy" stranger_things["The Body"] = "Shawn Levy" stranger_things["The Flea and the Acrobat"] = "The Duffer Brothers" stranger_things["The Monster"] = "The Duffer Brothers" stranger_things["The Bathtub"] = "The Duffer Brothers" stranger_things["The Upside Down"] = "The Duffer Brothers" episodes_directed(stranger_things, "The Duffer Brothers") episodes_directed(stranger_things, "Shawn Levy") episodes_directed(stranger_things, "Kerri Cobb") The following output is produced: The Duffer Brothers directed 6 episodes Shawn Levy directed 2 episodes Kerri Cobb directed 0 episodes Question Two. 50 points. Supply the missing class and methods so that when this code runs: # “Stranger Things” is the title of the series. # “The Duffer Brothers” is the creator of the series. # 1 is the number of seasons that the series has run. # 8 is the number of episodes that the series contains. stranger_things = Series("Stranger Things", "The Duffer Brothers", 1, 8) print(stranger_things) stranger_things.addSeason() # here comes the next season stranger_things.addEpisodes(9) # there are now 9 more episodes print(stranger_things) The following output is produced: Stranger Things has aired 8 episodes over 1 seasons. Stranger Things has aired 17 episodes over 2 seasons. Question Three. 25 points. Object Oriented Concepts. (a) What is the name of the constructor method in a class? (b) Suppose the class Athlete is already defined and we want to define a new class called Runner that is a subclass of Athlete. Complete the following one line of Python: class Runner (c) In the context of the Athlete class, give a concrete example of the difference between an instance and an instance variable. (d) Describe briefly the difference between a reader method and a writer method. (e) To override the + operator, an __add__ method can be defined in a class. What method must be defined to override the ** operator? .