How does a computer play "20 Questions"? It uses a Decision Tree.
It asks a question, splits the data, and asks again. Let's help Robo guess the animal!
We use Nested Ifs (an `if` inside an `if`).
if swims == "yes":
if quacks == "yes":
print("Duck")
Our mystery animal swims but does NOT quack. Set the variables.
swims = "yes" quacks = "no"
Write the outer if to check if it swims.
if swims == "yes":
# We will put more logic here
print("It likes water")
else:
print("It is a Cat")
Inside the first `if`, check if it quacks. If not, it's a Fish!
if swims == "yes":
if quacks == "yes":
print("Duck")
else:
print("Fish")
1. Why is it called a "Decision Tree"?