Level 4: States - IncrediCoders/Python1 GitHub Wiki
SideWinder added this page on June 6, 2025
Hi Paul, and I guess whoever else is reading this! I wrote you this bonus article about States, because I'm like the best friend ever!
In addition to this bonus article, you can find another bonus article on topics I showed you in Level 4: For Loops and Elif
Learn about For States
In coding, a state describes what something is like right now, its current condition. A state can be whether something is on or off, moving or still, or open or closed.
Think of Paul Python at IncrediCoders Academy. Is he sitting in class? Walking to lunch? Playing in the playground? Each one is a different state.
Why States Matter
States help your program make decisions and react to changes. For example, a game character might only jump if the “jumping” state is false, or a door might only open if the state is locked = false. Knowing the state of something lets your code decide what should happen next.
Python Example
In Python, we usually keep track of state using variables that store the current condition.
Scenario:
Paul Python has a door in his classroom. It should only open if it's unlocked.
door_locked = False
if door_locked == False:
print("The door opens.")
else:
print("The door is locked.")
Output:
The door opens.
Here, door_locked
is the state. It tells us whether the door should open or stay closed.
Comparing Programming Languages
Most programming languages use variables to keep track of state, then check that state with if statements.
For example, checking if a light is on or off.
Python
light_on = True
if light_on:
print("The light is shining.")
Java
boolean lightOn = true;
if (lightOn) {
System.out.println("The light is shining.");
}
C#
bool lightOn = true;
if (lightOn) {
Console.WriteLine("The light is shining.");
}
What’s the Difference?
- All three use a true/false variable to store the state (
light_on
,lightOn
, orlightOn
). - The if statement checks that state and responds.
- Python uses
True
andFalse
and is the easiest to read. - Java and C# are a little longer, but they do the same thing.
States are how your program remembers what’s going on. Just like Paul Python knows if he’s in class or at recess, your code needs to know the state so it can act the right way.
Learn More
TBD
Next Steps
Next, you can take on the two extra challenges to add to your Space Wars program and learn more! When you're done, you can move on to Level 5, the Creeper Chase!
Take the Challenges!
-
Challenge 1: In this challenge, you are going to add sound to the game when projectiles are fired!
-
Challenge 2: In this challenge, you are going to write code that will add asteroids to the game!
More Level 4 Resources
In addition to this Help page and the instructions for our Level 4 challenges, we also have Online Articles, a Learning Quiz, an Unplugged Activity, and a Rewards article:
-
Level 4: Online Articles - I made you a list of different web pages I found, which will help you learn more about creating the Space Wars program.
-
Level 4: Learning Quiz - I wrote some questions in case you want to quiz yourself about what you learned. Or you can teach others and quiz them!
-
Level 4: Unplugged Activity - I wrote this page with more details than what you saw in the book. You're going to recreate the SpaceWars game in person! You'll get a chance to review and practice key events and how they work with spaceships.
-
Level 4: Rewards - If you completed the Space Wars project, then you're welcome to check out this page as a reward. You can see some illustrations of me and learn more about who I am! You'll also find the Goth Award digital download, to show off your accomplishment!
Level 5
After you're completely done with Level 4 (did you do the challenges?), then it's time to move on to Level 5! While you read through Level 5 in your book, you can check out the resources from Intelli-Scents, as she teaches you how to build the Creeper Chase program:
I hope you had fun learning about space wars!
-- SideWinder