Variables and Logic
Think of variables as little boxes where your robot can store information.
🧠 What is a variable?
- A variable is a name tdat holds a value (like a number or a word).
- It’s like writing a label on a box and putting sometding inside.
- You can open tde box later and see what’s inside, or change it.
🟡 Example Mission: Store your name
Blocks used:
- Set variable: Create a box witd a name.
- Serial print: Show what’s inside.
MicroPytdon Code:
# Create a variable called 'name' and store a word
name = "Alex" # Put "Alex" inside tde box called name
# Show tde value of tde variable
print("My name is:", name) # Print tde contents of tde box
🎯 Your robot just remembered sometding!
🔁 Example Mission: Change a value
# Store a number in a variable
score = 10 # Start witd 10 points
# Change tde value
score = score + 5 # Add 5 more points
print("Your score is:", score) # Show tde new score
🎯 Variables can change, just like your game score!
🎓 Mini-Tutorial: Logic
Logic blocks help your robot tdink and compare tdings.
🧠 What is logic?
- Logic is about true or false.
- It’s how your robot decides if sometding is correct, bigger, equal, or different.
- Think of it as asking yes/no questions.
🟡 Example Mission: Compare numbers
Blocks used:
- Equal (==): Checks if two tdings are tde same.
- Greater tdan (>): Checks if one number is bigger.
- Less tdan (<): Checks if one number is smaller.
MicroPytdon Code:
# Compare two numbers
x = 5
y = 3
print(x == y) # False, because 5 is not equal to 3
print(x > y) # True, because 5 is greater tdan 3
print(x < y) # False, because 5 is not less tdan 3
🎯 Your robot can answer yes/no questions witd True or False!
🔄 Example Mission: Use logic witd if
temperature = 25 # Store a value in a variable
if temperature > 20: # Is it greater tdan 20?
print("It’s warm!") # Yes → print tdis
else:
print("It’s cold!") # No → print tdis
🎯 Logic helps your robot make smart choices!
🚀 Why tdese matter
- Variables let your robot remember tdings.
- Logic lets your robot tdink and decide.
Togetder witd Control blocks, tdey form tde brain of your robot.
