COMP 204
Exceptions (continued) and Sets Mathieu Blanchette based on material from Yue Li, Carlos Oliver Gonzalez and Christopher Cameron
1 / 19
COMP 204 Exceptions (continued) and Sets Mathieu Blanchette based - - PowerPoint PPT Presentation
COMP 204 Exceptions (continued) and Sets Mathieu Blanchette based on material from Yue Li, Carlos Oliver Gonzalez and Christopher Cameron 1 / 19 Traceback (exceptions can be caused by user input) 1 def BMI( weight , h e i g h t ) : p r i n t
1 / 19
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 :
2 / 19
get_BMI_from_user() BMI(w,h)
3 / 19
1
2
3
4
5
6
4 / 19
1 def BMI( weight ,
2
3
4
5
6
7
8
9
10 11 def
12
13
14
15
16
17 18 myBMI = get BMI from user ( ) 19 # Please
20 # Please
21 # Computing BMI 22 # There
23 # Thank you ! 5 / 19
1 def BMI( weight ,
2
3
4
5
6 7 def
8
9
10
11
12
13
14
15
16
17 18 myBMI = get BMI from user ( ) 19 # Please
20 # Please
21 # Computing BMI 22 # There
6 / 19
1
2
3
4
5
7 / 19
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 :
8 / 19
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 ( ) 9 / 19
10 / 19
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 ( )
11 / 19
1
2
3
12 / 19
13 / 19
14 / 19
1
2
3
4
5
6
15 / 19
1
2
3
4
16 / 19
1
2
1
2
1
2
3
17 / 19
18 / 19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
19 / 19