-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path39_classification_tree.py
37 lines (31 loc) · 1.31 KB
/
39_classification_tree.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
#Start with a flag set to true, since we need to ask the user at
#least once for an input (otherwise the program wont run)
ask_for_skin = True
while ask_for_skin:
skin = input("What type of skin does the animal have? ")
#We have a user input, but we haven't validated it yet. Since
#we already have an if/elif/else block that catches invalid input
#we can simply assume the input is correct here, and if we arrive
#at the else statement (which we know means invalid input was
#given) then we will change the flag to ask for input again (since
#we now know that the input given was invalid
ask_for_skin = False
if skin == "fur":
print("mammal")
elif skin == "feathers":
print("bird")
elif skin == "scales":
print("fish")
elif skin == "skin":
dry_or_moist = input("Is the skin moist or dry? ")
if dry_or_moist == "dry":
print("reptile"0
elif dry_or_moist == "moist":
print("amphibian")
else:
print("skin must be either dry or moist")
#Since this else catches all invalid input, if we get here then we
#know the input was invalid and we need to ask for input again
else:
print("not a proper skin type, please try again")
ask_for_skin = True