COMP 204
Exceptions Mathieu Blanchette based on material from Yue Li, Carlos Oliver Gonzalez and Christopher Cameron
1 / 31
COMP 204 Exceptions Mathieu Blanchette based on material from Yue - - PowerPoint PPT Presentation
COMP 204 Exceptions Mathieu Blanchette based on material from Yue Li, Carlos Oliver Gonzalez and Christopher Cameron 1 / 31 Bugs: when things break I You will probably have noticed by now that things dont always go as expected when you try
1 / 31
1Wikipedia 2 / 31
3 / 31
1
2
3
4
5
6
7
2Noam Chomsky (1955) 4 / 31
3Noam Chomsky (1955) 5 / 31
1
2
3 4
5
6
, → 6 / 31
1
2
3
4
5
6
7
8
7 / 31
1
2
3 4
5
6
7
8 / 31
1
2
3 4
5
6
, → 7 8
9
10
9 / 31
10 / 31
1
2
3
4
5
6 7
8
9
10
11
12
13
14
11 / 31
1 def BMI( weight ,
2
3
4
5
6 7 def
8
9
10
11
12 13 myBMI = get BMI from user ( ) 14 # Output : 15 # Please
16 # Please
17 # Computing BMI 18 # Traceback
19 #
20 #
21 #
22 #
23 #
24 #
25 # b u i l t i n s . Z e r o D i v i s i o n E r r o r :
12 / 31
get_BMI_from_user() BMI(w,h)
13 / 31
1
2
3
4
5
6
14 / 31
1 def BMI( weight ,
2
3
4
5
6
7
8
9
10 11 def
12
13
14
15
16
17
18
19
20
21 22 myBMI = get BMI from user ( ) 23 24 # Output : 25 # Please
26 # Please
27 # Computing BMI 28 # There
15 / 31
1
2
3
4
5
6
7
8
, → 9
10
16 / 31
1 # This BMI f u n c t i o n
2 # i f
3 def BMI( weight ,
4
5
6
7
8 9 def
10
11
12
13
14
15 16 myBMI = get BMI from user ( ) 17 18 # Traceback
19 #
20 #
21 #
22 #
23 #
24 #
25 # b u i l t i n s . ValueError :
17 / 31
1 # This BMI f u n c t i o n
2 # i f
3 def BMI( weight ,
4
5
6
7
8 9 def
10
11
12
13
14
15
16
17
18
19 20
21 22 myBMI = get BMI from user ( ) 18 / 31
19 / 31
1 def BMI( weight ,
2
3
4
5
6 7 def
8
9
10
11
12
13
14
15
16
17
18
19
20
21 22
23 24 myBMI = get BMI from user ( ) 20 / 31
1 def BMI( weight ,
2
3
4
5
6 7 def
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 23 myBMI = get BMI from user ( ) 21 / 31
1 def
2
3
4
5
6 w h i l e
7
8
9
10
11
12
13
14
15
16
17
22 / 31
1 import
2 # standard
3
4 5 # p r i n t i n g
6
7
8 9 grades = { ' Sjoerd ' :
10 f o r
11
12
13 14 #output : 15 # p i
16 # p i
17 # p i
18 # Sjoerd
19 # Jack
20 # Annie
23 / 31
24 / 31
1
2
3
4
, → 5
6
7
8
9
10
11
12
13
14
25 / 31
1
2
3
26 / 31
1
2
3
4
5
6
7
27 / 31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 17
28 / 31
1 f i r s t N a m e s = [ ' Amol ' , 'Ahmed ' , ' Ayana ' ] 2 lastNames = [ ' Prakash ' , ' ElKhoury ' , ' Jones ' ] 3 # without
4 # i s
5 fullNames = [ ] 6 f o r
7
8
9 # or 10 fullNames = [ ] 11 f o r
12
13
14 # This
15 fullNames = [ ] 16 f o r
17
18
19 #output : 20 # [ ' Amol Prakash ' ,
29 / 31
30 / 31
1
2
3
4
5
6
31 / 31