CHAPTER 5

The Crossroads 🚧

Imagine a path divided in two. To the left is a treasure chest. To the right is a dragon! 🐉

Computers make these decisions using if and else. It's like a gatekeeper.

🚦 If This, Then That

We check a condition. If it is True, we do the indented code.

password = "Open"

if password == "Open":
    print("Welcome!")
else:
    print("Go Away!")
⚠️ WATCH THE INDENTATION!
Python needs 4 spaces (or tab) before the print. It tells Python "This print belongs to the if".
Also notice the double equals == for checking!

YOUR QUESTS ⚔️

Quest 1: The Gatekeeper

Ask the user "What is the password?" using input() and save it in secret.

secret = input("What's the password?")
Waiting for you to run code...

Quest 2: Check the Password

Add the check! If the password is "Melon", print "Enter friend".

if secret == "Melon":
    print("Enter friend")

Don't forget the colon : and the indentation!

Locked 🔒

Quest 3: The Trap

Add an else: block to print "Wrong!" if they don't say Melon.

Locked 🔒

Wizard's Exam 📜

1. How do you check if 'a' is equal to 'b'?

⌨️ EDITOR
Waiting for code...