11import math
22
3-
43def age_band_5_years (age : int )-> str :
54 """
65 Place age into appropriate 5 year band
@@ -22,24 +21,26 @@ def age_band_5_years(age: int)->str:
2221 --------
2322 >>> age_band_5_years(3)
2423 '0-4'
25- >>> age_band_5_years(-1 )
24+ >>> age_band_5_years(None )
2625 'Age not known'
2726 >>> age_band_5_years(95)
2827 '90 and over'
2928 """
3029
31- if age is None or age < 0 :
30+ if age is None :
3231 return 'Age not known'
3332
34- if age > 89 :
35- if age < 150 :
36- return '90 and over'
33+ if age >= 90 :
34+ if age >= 150 :
35+ raise ValueError ( "The age input: {} is too large." . format ( age ))
3736 else :
38- raise ValueError
39-
40- lowerbound = 5 * int (math .floor (age / 5 ))
41- upperbound = lowerbound + 4
42- return '{}-{}' .format (lowerbound , upperbound )
37+ return '90 and over'
38+ elif age < 0 :
39+ raise ValueError ("The age input: {} is too low." .format (age ))
40+ else :
41+ lowerbound = 5 * int (math .floor (age / 5 ))
42+ upperbound = lowerbound + 4
43+ return '{}-{}' .format (lowerbound , upperbound )
4344
4445
4546def age_band_10_years (age : int )-> str :
@@ -63,21 +64,23 @@ def age_band_10_years(age: int)->str:
6364 --------
6465 >>> age_band_10_years(3)
6566 '0-9'
66- >>> age_band_10_years(-1 )
67+ >>> age_band_10_years(None )
6768 'Age not known'
6869 >>> age_band_10_years(95)
6970 '90 and over'
7071 """
7172
72- if age is None or age < 0 :
73+ if age is None :
7374 return 'Age not known'
7475
75- if age > 89 :
76- if age < 150 :
77- return '90 and over'
76+ if age >= 90 :
77+ if age >= 150 :
78+ raise ValueError ( "The age input: {} is too large." . format ( age ))
7879 else :
79- raise ValueError
80-
81- lowerbound = 10 * int (math .floor (age / 10 ))
82- upperbound = lowerbound + 9
83- return '{}-{}' .format (lowerbound , upperbound )
80+ return '90 and over'
81+ elif age < 0 :
82+ raise ValueError ("The age input: {} is too low." .format (age ))
83+ else :
84+ lowerbound = 10 * int (math .floor (age / 10 ))
85+ upperbound = lowerbound + 9
86+ return '{}-{}' .format (lowerbound , upperbound )
0 commit comments