Welcome to the GLAB-370.1.2! In this lab, you will embark on an exciting adventure into the world of if-else statements in Python. Get ready to unravel the mysteries of decision-making as you explore the depths of conditional logic. But don't worry, we'll make it fun along the way!
To fully enjoy this lab, you should have a basic understanding of Python syntax
As you step into this peculiar land, you'll encounter an if-else statement like no other. Brace yourself and prepare to be amazed. Here's a simple example to get you started:
# The Enchanted Door
password = input("Enter the secret password: ")
if password == "Open Sesame":
print("The door opens wide. Welcome!")
else:
print("The door remains closed. Access denied!")
To witness the power of this mystical if-else statement, follow these steps:
- Open your favorite Python IDE or a text editor.
- Create a new Python file and save it with a whimsical name like "if_else_adventure.py".
- Copy the code snippet from Step 1 into your file.
- Save the file and run it.
Now it's your turn to dive into the enchanting realm of if-else statements. Unleash your creativity and write your own code snippets using if-else statements. Need some inspiration? Here are a few ideas to get you started:
-
The Potion Conundrum: Write a program that asks the user for their age. If they are under 18, display a message saying they can't drink the magic potion. Otherwise, grant them access to the secret potion recipe.
-
The Riddle of the Sphinx: Create a riddle game where the user has to guess the correct answer. If they guess right, congratulate them on their wisdom. Otherwise, bewilder them with a clever hint.
-
The Tricky Troll: Imagine a troll guarding a bridge. Prompt the user to answer a riddle. If they answer correctly, they may pass unharmed. Otherwise, well... let's just say they'll have a bumpy journey.
Remember, the sky's the limit! Feel free to come up with your own if-else adventures. Get creative, be playful, and have fun!
Once you've completed your if-else adventures, share your magical creations with your instructor.
Congratulations on completing The Great If-Else Adventure! You've mastered the art of decision-making through if-else statements and discovered the fun side of programming. Take these newfound skills and continue your journey into the vast realms of Python programming. The magical world awaits your exploration!