CSC148H1 Study Guide - Midterm Guide: Docstring, Init
katrinasavvy and 38715 others unlocked
1
CSC148H1 Full Course Notes
Verified Note
1 document
Document Summary
Read over the denition of this python function: def c(s): """docstring (almost) omitted. """ return sum([c(i) for i in s]) if isinstance(s, list) else 1. Work out what each function call produces, and write it in the space provided: c(5) 3: c(["one", [2, "three"], 4, [5, "six"]]) 6: c(["one", [2, "three"], 4, [5, [5. 5, 42], "six"]]) Read over the declarations of the three exception classes, the denition of raiser, and the supplied code for notice below. Then complete the code for notice, using only except blocks, and perhaps an else block. class specialexception(exception): pass class extraspecialexception(specialexception): pass class ultraspecialexception(extraspecialexception): pass def raiser(s: str) -> none: """raise exceptions based on length of s. """ if len(s) < 2: raise specialexception elif len(s) < 4: raise extraspecialexception elif len(s) < 6: = 1 / int(s) def notice(s: str) -> str: # write some "except" blocks and perhaps an "else" block.