Level 2: Conditional Statements: If Else - 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 Conditional Statements: If Then Else 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, Variables, Initialization Files, Displaying Text, and While Loops.

Learn about Conditional Statements: If Else

An If-Then-Else statement allows your program to make decisions. It checks a condition, such as a yes/no question, and then runs different code depending on whether the answer is true or false.

Why If-Then-Else Matters

Programs often need to choose what to do next, depending on what’s happening. Without decision-making, your code would do the same thing every time. But with If-Then-Else, your code can react and adjust.

For example, every day, Paul Python uses If-Then-Else logic for his decision to go to IncrediCoders Academy: “If today is a school day, then go to class. Else, stay at home.”

Python Example

In Python, If-Then-Else lets your program check something and do different things based on the answer.

Scenario: Paul Python wants to know if today is a school day. If it is, he’ll go to school. If not, he’ll stay home and relax.

school_day = True

if school_day:
    print("Paul Python goes to IncrediCoders Academy!")
else:
    print("Paul Python stays home and plays games!")

What’s happening here:

  • If school_day is True, Paul goes to school.
  • If school_day is False`, he stays home.

Comparing Programming Languages

Most programming languages use If-Then-Else statements to let the code make decisions. While the idea is the same, the way it’s written (syntax) is a little different in each language.

Python

cold = True

if cold:
    print("Wear a jacket!")
else:
    print("Wear a t-shirt!")

Java

boolean cold = true;

if (cold) {
    System.out.println("Wear a jacket!");
} else {
    System.out.println("Wear a t-shirt!");
}

C#

bool cold = true;

if (cold)
{
    Console.WriteLine("Wear a jacket!");
}
else
{
    Console.WriteLine("Wear a t-shirt!");
}

What’s the Difference?

In all three languages, the idea is the same: check a condition and do one thing or the other. However:

  • Python uses plain words and colons : to start each block of code.
  • Java and C# use parentheses () and curly braces {} to organize their code.
  • In Java and C#, you also need to say what kind of data you're using (like boolean or bool for true/false).

Even though the syntax is different, If-Then-Else works the same everywhere, it helps your program make smart decisions!

Learn More

TBD

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 Conditional Statements: If Then Else! They are an essential part of Python programming.

-- Mrs. Scratcher

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