top of page

Learn Python with Super Mario: Variables, Print Function, and Conditionals 🎮

Updated: Sep 21, 2023

Hey, Super Mario fans! 🌟

Today, we're going to explore Python, a fantastic programming language that helps us build games like Mario 🕹️. We'll learn about variables, the print function, and conditionals. Get ready for a fun adventure! 🚀


Contents:


 

Python Variables: Mario's Coins 💰


Imagine you're playing Mario, and you want to keep track of the number of coins you've collected 💰. In Python, we can use variables to store this information. A variable is like a box 📦 where you can keep things, like the number of coins you've collected.


To create a variable, you need to give it a name and a value. Let's name our variable coins and set its value to 0:

coins = 0

Now our coins variable has a value of 0. Every time Mario collects a coin, we can add 1 to the coins variable, like this:

coins = coins + 1


 

Print Function: Showing Mario's Coins 📢


Now that we have a variable to store the number of coins, we want to show it on the screen 💻. In Python, we do this using the print function. It's like shouting, "Hey, look at my coins!" 📢 To print the number of coins, we can write:

print(coins)

This will show the value of the coins variable on the screen. If coins is 5, it will print 5.


🎨 Printing with Style: Combine Text and Numbers!


We can make our messages even more fun by combining text and numbers using the print() function. Let's print a message that tells us how many coins Mario has collected:

coins = 50 
print("Mario has collected", coins, "coins!")

In this example, we use commas (,) to combine the text and the number inside the print() function. Our program will display "Mario has collected 50 coins!" on the screen.


Now you know how to use the print() function to make your Python programs talk to you! Keep practicing and have fun making your code share messages, numbers, and more with the world! 🌈🖨️

 

🚦 What are Conditionals?


Conditionals are like traffic lights in Python. They help Mario decide which way to go, depending on different situations. In Python, we use if, elif, and else to create conditionals. These keywords help us write code that makes decisions based on certain conditions. Let's explore how they work!


🌟 The if Statement: Mushroom Power-Up!


Imagine Mario finds a box 📦 with a magic mushroom 🍄 inside. He can use the mushroom to grow bigger and gain extra strength! But he needs to check if it's really a magic mushroom. We can use an if statement to help him:


mushroom = "magic"
if mushroom == "magic":    
	print("Mario grows bigger! 🍄") 


In this example, the if statement checks if the mushroom is "magic". If it is, Mario grows bigger! If the mushroom was something else, nothing would happen.


🚧 The elif Statement: Jump or Slide?

Now, Mario encounters an obstacle! It could be a pipe 🚇 or a wall 🧱. We can use an elif statement to help him decide whether to jump or slide:


obstacle = "pipe"
if obstacle == "wall":
     print("Mario jumps over the wall! 🏃‍♂️") 
elif obstacle == "pipe":
     print("Mario slides down the pipe! 🚇") 

In this adventure, the elif statement helps Mario choose a different action based on the obstacle. If it's a wall, he jumps; if it's a pipe, he slides!


💥 The else Statement: Defeat the Enemy!


Mario runs into different enemies like Goombas or Koopa Troopas 🐢. We can use an else statement to help him defeat the enemy, no matter what it is:


enemy = "Goomba"
if enemy == "Koopa Troopa":
     print("Mario stomps on the Koopa Troopa! 💥") 
else:
     print("Mario defeats the", enemy, "!") 

Here, the else statement helps Mario defeat any enemy that isn't a Koopa Troopa. If it's a Goomba or something else, he still wins the battle!


Now you know how Python conditionals help Super Mario make decisions in his quest to save Princess Peach! Keep practicing, and have fun exploring the world of coding with your favorite video game character! 🌟🎮


Exercise 1:


Exercise 2:




The End 🎉


That's it! Now you know about Python variables, the print function, and conditionals 🎉. Keep practicing, and soon you'll be a Python master 🥇, just like Mario is a hero in his games!


Remember, learning programming is like playing Super Mario - the more you practice, the better you get! 🏃‍♂️ So, get ready to write more Python code and explore the exciting world of programming! 🌍

Comments


bottom of page