CHAPTER 3

The Mystery Fruit 🕵️‍♂️

Robo found a mystery fruit on the floor. It looks partly Red and partly Yellow.
Is it an Apple or a Banana?

To decide, Robo measures the Distance. Who is it closer to?

📏 Calculating Distance

In math, distance is just the Difference. We use abs() (Absolute Value) so it's always positive.

apple = 10
mystery = 8
distance = abs(apple - mystery) # Result: 2

Who is the "Nearest Neighbor"? The one with the Smallest Distance!

SOLVE THE CASE 🔍

Step 1: The Suspects

Define the fruits by size.
Apple=10, Banana=20.
The mystery fruit is size 12.

apple = 10
banana = 20
mystery = 12
Waiting for you to run code...

Step 2: Measure Distance

Calculate distance to apple (`a_dist`) and banana (`b_dist`). Tips: Use abs(a - b).

a_dist = abs(apple - mystery)
b_dist = abs(banana - mystery)
print(a_dist)
print(b_dist)
Locked 🔒

Step 3: The Verdict

Write an if statement. If `a_dist` is smaller (`<`) than `b_dist`, it's an Apple!

if a_dist < b_dist:
    print("It is an Apple!")
else:
    print("It is a Banana!")
Locked 🔒
🤔

Logic Check 📝

1. If Apple is at 10 and Mystery is at 100, is the distance small or big?

⌨️ INVESTIGATION
Waiting...