Level 1: Methods - IncrediCoders/Python1 GitHub Wiki

GitHubAvatarPoint

Grafika Turtle added this page on March 14, 2025


Here is a bonus article that will tell you more about what Methods means in computer programming!

In addition to this bonus article, you can find other bonus articles that teach you the topics I covered in Level 1: Object‐Oriented Programming, Troubleshooting & Error Handling, Turtle Graphics, Syntax, and Comments.

Learn About Methods

A method is like a mini-program inside an object. It’s a set of instructions that the object can run when asked. You can think of a method as something an object can do.

For example, if Paul Python is an object, a method could be walk_to_school() or say_hello(). Instead of writing the same code over and over, you just call the method whenever you want that action to happen.

Why Methods Matter

Methods make your code easier to read and reuse. Instead of writing long steps every time, you just give the object a command using its method. It’s like giving your character a button that says, “Do this!”

Python Example

In Python, methods are like special functions that belong to an object.

Scenario:

Paul Python builds a robot. The robot can wave and jump using methods.

class Robot:
    def wave(self):
        print("Hello!")

    def jump(self):
        print("Jumping up!")

# Create a robot object
my_robot = Robot()

# Use the robot's methods
my_robot.wave()
my_robot.jump()

Output:

Hello!
Jumping up!

Each method (wave, jump) is something the robot knows how to do. You can tell it to do those things any time.

Comparing Programming Languages

Methods work similarly across most programming languages, but the way you write them (syntax) is a little different.

Scenario: Let’s create a robot with a say_hello() method in Python, Java, and C#.

Python

class Robot:
    def say_hello(self):
        print("Hello!")

Java

public class Robot {
    public void sayHello() {
        System.out.println("Hello!");
    }
}

C#

public class Robot {
    public void SayHello() {
        Console.WriteLine("Hello!");
    }
}

What’s the Difference?

  • All three use methods to tell an object what it can do.
  • Python is the simplest, just def and a print line.
  • Java and C# need extra pieces like public and type names (void), but they follow the same idea.

Methods are like action buttons on your objects. Once you create them, your objects are ready to do cool stuff, just press the right button.

Learn More

TBD

Next Steps

Next, if you need help completing the Turtle Map project in the book, you can find help at Level 1: Help.

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

Take the Challenges!

  1. Challenge 1: On this page, I show you how to map a different route to our school, the IncrediCoders Academy. This time, we're going to cross the bridge, over the lake.

  2. Challenge 2: For this challenge, I'll show you how to create a loop, so that you can have the turtle go back and forth between my house and the school, five times.

More Level 1 Resources

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

  • Level 1: Online Articles - I made you a list of different web pages I found, which will help you learn more about Turtle Graphics.

  • Level 1: 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! You'll find the answers to the quiz in the Level 1 Solutions folder.

  • Level 1: 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 Turtle, and one person is the Programmer!

  • Level 1: Rewards - If you completed the Turtle Map project that we talked about in the car, then I set up this page to be your reward. You can see some illustrations of me and learn more about who I am! You'll also find the Turtle Award digital download, to show off your accomplishment!

Level 2

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

I hope you had fun learning about the concept of Syntax! After all, my brother was named after it!

-- Grafika Turtle

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