CSC148H1 Study Guide - Midterm Guide: Docstring, Init

52 views4 pages
25 Oct 2018
School
Course
Professor
katrinasavvy and 38715 others unlocked
CSC148H1 Full Course Notes
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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents