-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.py
66 lines (49 loc) · 1.8 KB
/
validator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Validator:
def validate_weight(self, weight):
"""
Validates the entered weight.
Args:
weight: The input weight value (string).
Returns:
True if the entered weight is in the range 40-300 kg, False otherwise.
"""
# Attempts to convert the entered weight to a float.
try:
weight_float = float(weight)
except ValueError:
# If the conversion fails, returns False (invalid value).
return False
# Checks if the entered weight is in the range 40-300 kg.
return 40 <= weight_float <= 300
def validate_age(self, age):
"""
Validates the entered age.
Args:
age: The input age value (string).
Returns:
True if the entered age is in the range 10-120, False otherwise.
"""
# Attempts to convert the entered age to an integer.
try:
age_int = float(age)
except ValueError:
# If the conversion fails, returns False (invalid value).
return False
# Checks if the entered age is in the range 10-120.
return 10 <= age_int <= 120
def validate_height(self, height):
"""
Validates the entered height.
Args:
height: The input height value (string).
Returns:
True if the entered height is in the range 100-250 cm, False otherwise.
"""
# Attempts to convert the entered height to a float.
try:
height_float = float(height)
except ValueError:
# If the conversion fails, returns False (invalid value).
return False
# Checks if the entered height is in the range 100-250 cm.
return 100 <= height_float <= 250