Level 2: Variables - IncrediCoders/Python1 GitHub Wiki

Scratcher_PointSide

Mrs. Scratcher added this page on March 14, 2025


Hello class! I prepared this bonus article that will help explain Variables in Python programming!

In addition to this bonus article, you can find other bonus articles that teach you the topics I covered in Level 2: Events, Conditional Statements: If Then Else, Initialization Files, Displaying Text, and While Loops.

Learn about Variables

A variable is like a labeled box that stores information in your program. You can put something inside, change what's inside, or check what's inside later. Variables help you remember values while your program is running.

Think of a variable like a pencil case: you can put something in it like your pencils and erasers, take it out, or swap it for something else. You just need to remember what you called your pencil case.

Why Variables Matter

Variables are used in almost every program. They let you store and reuse information like numbers, names, scores, or even whether something is on or off. Without variables, your program wouldn’t be able to remember anything.

Python Example

In Python, creating a variable is super simple. You just name it, use =, and then give it a value.

Scenario: Paul Python is keeping track of how many pencils he has.

pencils = 5

print("Paul has", pencils, "pencils.")

pencils = pencils - 1  # He gives one pencil to Grafika Turtle

print("Now Paul has", pencils, "pencils.")

Paul starts with 5 pencils, then gives one away to Grafika Turtle, so now he has 4.

The variable pencils remembers his pencil count.

Comparing Programming Languages

Scenario: We want to store how many apples Paul Python has.

Python

apples = 3

Java

int apples = 3;

C#

int apples = 3;

What’s the Difference?

  • Python doesn’t need you to say what kind of value the variable holds.
  • Java and C# need you to be more specific. You have to tell them the type, like int for a whole number.
  • All three languages use = to store a value in the variable.

No matter the language, variables let your program remember important information and use it again later.

Learn More

About Lists

Lists are also very similar to variables! But with a list, you're more likely to put together a list for your program and not change what's in each spot in the list as often as you might change what's in a variable.

For example, if the user enters 10 items into a grocery list, you'll want to capture that into a list. Each item in the list probably isn't going to change too often (unless the user starts over and builds a new list).

Annie Conda talks about lists a lot more in Level 3. To learn more about lists in Python, see Level 3: Lists.

Next Steps

Next, if you need help completing your Class Introductions assignment from the book, go to Level 2: Help.

After you complete Level 2 in the book, you can take on the two extra challenges to add to your Class Introductions program and learn more! When you're done, you can move on to Level 3, the Classroom Quiz!

Take the Challenges!

  1. Challenge 1: Add the introduction for RAM and ROM and one for Amphib Ian, totaling 14 introductions!

  2. Challenge 2: Instead of using an if/else ladder, you will put the text and images into a Python list (it's a list of variables).

More Level 2 Resources

In addition to this Help page and the instructions for our Level 2 challenges, we also have Online Articles, a Learning Quiz, an Unplugged Activity, and a Rewards article:

  • Level 2: Online Articles - I made you a list of different web pages I found, which will help you learn more about variables, events, and if statements, in addition to what you're learning in our Class Introductions project.

  • Level 2: 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 2: Unplugged Activity - I wrote this page with more details than what you saw in the book. In this game, you'll have one person act as the developer, and one person act as the variable where the developer choose a noun for the variable to say in the story that they tell!

  • Level 2: Rewards - If you completed the Class Introductions project that we covered in class, then I set up this page to act as a reward. You can see some illustrations of me and learn more about who I am! You'll also find the Apple Award digital download, to show off your accomplishment! Make sure you complete the Level 2 project from the book first though!

Level 3

After you're completely done with Level 2 (did you do the challenges?), then it's time to move on to Level 3! While you read through Level 3 in your book, you can check out the resources from Mrs. Codala, as she teaches you how to build the Classroom Quiz program:


I hope you learned more about variables and lists! They are an essential part of Python programming.

-- Mrs. Scratcher

⚠️ **GitHub.com Fallback** ⚠️