Level 7: Classes - IncrediCoders/Python1 GitHub Wiki

Syntax Turtle added this page on June 6, 2025


Here is a bonus article that will tell you more about Classes!

In addition to this bonus article, you can find other bonus articles that teach you the topics I covered in Level 7: Dictionaries and Sets.

Learn About Classes

A class in programming is like a blueprint for something you want to build. It’s a way to group data, such as a name or color, and actions like moving or jumping, into one neat package.

If you were designing characters in a video game, each one could be built from the same class, but with different names, colors, and abilities.

Why Classes Matter

Classes help programmers organize their code. Instead of writing the same thing over and over, you can use a class to create many similar things, like students, pets, or game objects.

Python Example

In Python, a class starts with the word class, and you can give it any name you want. You then add attributes (things the object knows) and methods (things the object can do).

Scenario: Let’s create a class for a student at IncrediCoders Academy.

class Student:
    def __init__(self, name, grade):
        self.name = name
        self.grade = grade

    def say_hello(self):
        print("Hi, I'm " + self.name + " and I'm in grade " + str(self.grade))

# Let's make Paul Python a student
paul = Student("Paul Python", 5)
paul.say_hello()

This will print: Hi, I'm Paul Python and I'm in grade 5

The class defines how a student works, and Paul Python is one object made from that class.

Comparing Programming Languages

Most programming languages use classes to organize objects. The setup can look a little different, but the idea is the same.

Scenario: We’ll create a class named Student with a name and grade.

Python

class Student:
    def __init__(self, name, grade):
        self.name = name
        self.grade = grade

Java

public class Student {
    String name;
    int grade;

    public Student(String name, int grade) {
        this.name = name;
        this.grade = grade;
    }
}

C#

public class Student {
    public string name;
    public int grade;

    public Student(string name, int grade) {
        this.name = name;
        this.grade = grade;
    }
}

What’s the Difference?

  • Python uses self and has a special method called __init__ to start.
  • Java and C# need to write the type of each variable (like String or int) and use public to share them.

Learn More

Next Steps

TBD

Next, you can take on the two extra challenges to build more features for the IncrediCards game, and to learn more!

Take the Challenges!

  1. Challenge 1: In this challenge, you are going to add two more cards to each player's deck, so that you can switch between five cards (instead of three cards).

  2. Challenge 2: In this second challenge, you are going to add a second attack option, the Coded Attack (which has special abilities, like to get an extra turn).

More Level 7 Resources

  • Level 7: Unplugged Activity - I wrote this page with more details than what you saw in the book. In this game,

  • Level 7: Rewards - If you completed the IncrediCards program that we talked about, 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 WHAT Award digital download, to show off your accomplishment!

  • Level 7: IncrediCards - All Online Resources - Return back to the main Level 7 page, with all our online resources!

Level 7

After you're completely done with Level 6 (did you do the challenges?), then it's time to move on to Level 7! While you read through Level 7 in your book, you can check out the resources from CHARACTER, as he teaches you how to build the IncrediCards program:

Syntax and I love to make card games like IncrediCards! We hope you had fun learning about it too!

--Grafika and Syntax Turtle

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