Lecture 13: Exceptions and Modules
Craig Zilles (Computer Science) November 22, 2019 https://go.illinois.edu/cs105fa19
CS 105 Lecture 13: Exceptions and Modules Craig Zilles (Computer - - PowerPoint PPT Presentation
CS 105 Lecture 13: Exceptions and Modules Craig Zilles (Computer Science) https://go.illinois.edu/cs105fa19 November 22, 2019 To Today 1. Excel Power Example 2. Python Warmup 3. Exceptions try/except, multiple exceptions, across
Craig Zilles (Computer Science) November 22, 2019 https://go.illinois.edu/cs105fa19
2
ngl lookin pretty good rn feeling pretty good rn hope this finds you well i mean cmon i know its probably a little boring reading like 500 of these but I want you to GET PUMPED UP WOOOOOOOOOOOOOOOOO!!!!!!!!!! CAN YOU FEEL IT!!! CAN YOU!??? alright lets uhh simmer down just a little ok i got a little excited there but you know what i hope you got a little excited right there too yknow? I hope you can feel the energy im putting into this text yknow? cmooooon you feel it, ya? Ya you do ya hahhahaha we FEEELING IT NOWW! WOOOOOOOOOOOO!!! JUST STAND UP AND SHOUT WOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOO
3
Download the following CSV file which contains the number of fishing licenses sold in each county each year from 2005 to 2012 for the state of Illinois. Open it up and compute the total number of RES FISHING licenses sold in McHenry county in the years from 2005 to 2006 (inclusive). What if we wanted to compute this for all licenses and all counties?
4
A) VLOOKUP B) INDEX C) MATCH D) SUMIFS E) COUNTIFS
5
def test(num): if num > 0: return True return False A) True B) False C) first True and then False D) the tuple (True, False) E) an error occurs
6
prompt = 'type a number or q to quit\n' items = [] while True: item = input(prompt) if item == 'q': break items.append(float(item)) value = sum(items) / len(items) print(value)
7
prompt = 'type a number or q to quit\n' items = [] while True: item = input(prompt) if item == 'q': break items.append(float(item)) value = sum(items) / len(items) print(value)
8
A B C D E
management try: # do potentially bad things except: # handle bad things if they happen
9
try: # do potentially bad things except ValueException as e: # handle ValueExceptions # e is bound to exception object except ZeroDivisionError: # ... except: # handle any other exceptions
10
def f(): x = 1/0 print('hi') def g(): f() print('hello') g()
11
12
13
After: import useful How to call useful_function with "hi" as argument A) function("hi") B) useful_function("hi") C) useful.function("hi") D) useful.useful_function("hi") E) None of the above
14