Question: Part (c) [2 MARKS] Consider the following module: from typing import List def banana (1st: List[int]) -> float: return orange (1st) / len(1st) def orange
![Part (c) [2 MARKS] Consider the following module: from typing import](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f4e56a90be9_54666f4e56a2591f.jpg)
![List def banana (1st: List[int]) -> float: return orange (1st) / len(1st)](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f4e56b84538_54766f4e56b09a92.jpg)
![def orange (1st: List[int]) -> float: result = 1 for item in](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f4e56c66a48_54766f4e56bdb9a3.jpg)
Part (c) [2 MARKS] Consider the following module: from typing import List def banana (1st: List[int]) -> float: return orange (1st) / len(1st) def orange (1st: List[int]) -> float: result = 1 for item in lst: result = result * item return result def apple(1st: List[int]) -> float: b = banana (1st) return b + 5 == 7 if __name__ __main__': try: print(apple([])) except ZeroDivisionError: print('Ouch!') 1. How many stack frames are on the call stack, including the frame for raised? main, when an error is 2. When the error is raised, how many stack frames are popped off the stack before "Ouch!" is printed? [9 MARKS] This question includes several small short-answer questions. Use any editor to type your answers, and save them in a file called Q1 answers.txt. Hand in this file on Markus. Part (a) [4 MARKS] Suppose we have an abstract class called Monster with two implemented methods (an initializer, and a method called play) and one abstract method called learn. Assume each method has one parameter, which is a string. (It doesn't matter to this question what the methods do.) Suppose Monster has two subclasses: Godzilla and Werewolf. 1. Write 1-3 lines of client code that clearly demonstrates polymorphism. State the exact expres- sion that is polymorphic in your code. 2. What method do we know for sure Werewolf must implement? 3. Give one reason why Godzilla might define its own initializer? Be specific. Part (b) [3 MARKS] The built-in list class has a method reverse that mutates the list, putting it in reverse order. The follow- ing hypothesis test will check one aspect of this method. Write the body of test reverse_same_length. @given(lists (integers())) def test_reverse_same_length(1st: List): "! "Test that reverse does not change the length of the list
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
