Discover what Python is, why it is popular, and write your first program.
You know that moment in an RPG when you unlock a new ability and suddenly everything changes? You can access new areas, solve puzzles you used to skip, do things you never thought possible. Well, that is about to happen to you right now, except in real life. The ability you are unlocking today is called Python.
Python is a programming language, meaning it is a way to tell the computer what to do. But not just any language, it is considered one of the friendliest programming languages in the world. If other languages look like a recipe written in hieroglyphs, Python looks almost like a normal sentence in English. And that makes it perfect for someone just getting started.
By the end of this lesson, you will have already written your first program. Seriously. Not in a week, not after ten tutorials, today. Let's go.
In this lesson you begin building Python Kingdom, a text RPG game where your hero will traverse 9 lands to defeat the evil Dark Bug. In each lesson you will add a new feature to the game, and by the end you will have a complete RPG! Today you create the title screen, the kingdom map, and the story introduction, using print() and comments.
Python was created in 1991 by a Dutch programmer named Guido van Rossum. And do you know where the name comes from? Not from the python snake, as you might think. Guido was a fan of the British comedy group Monty Python, so he decided to give the language this funny name. So yes, programming can be fun too.
The idea behind Python was simple: create a language that people could read easily, not just computers. And he succeeded. Today, Python is used by millions of people around the world, from high school students to engineers at the biggest tech companies.
You might be wondering: "There are a ton of programming languages out there. Why Python?" Here are a few solid reasons:
Let me give you some concrete examples to give you an idea:
To write and run Python code, you have a few options. The fastest way to get started is to use an online editor right in your browser, without installing anything. I recommend repl.it. Go to the site, create a free account, choose "Python" as the language, and you are good to go.
If you want to work on your own computer, you can download Python from python.org and use a code editor like Visual Studio Code. But for now, repl.it is more than enough.
There is a tradition in programming: the first thing you do when learning a new language is to display the message "Hello, World!" on screen. It is like a greeting you give to the programming world. Let's honor the tradition:
That is it. One single line. When you run this code, the screen will show:
Hello, World!The print() function is the one doing the magic. You give it some text between quotes and it displays it on screen. Simple and elegant.
Now that you understand the basic idea, let's experiment a little. You can display any message you want:
Each print() displays its text on a new line. So the result would be:
Hi, I am a 9th grade student!
I like to play Minecraft.
Today I am learning Python!You can glue two texts together using the + operator. This is called concatenation (a fancy word that simply means "joining"):
Will display:
My name is AlexPay attention to the space after "is ". Without it, the texts would stick together directly and you would get "My name isAlex", which does not look great.
You can also use print() with numbers, without quotes:
Will display 15, because Python calculates the result before displaying it.
When you write code, sometimes you want to leave a note for yourself or for someone else reading the code. Maybe you want to explain why you did something in a certain way. That is what comments are for.
In Python, a comment starts with the # symbol. Everything after # on that line is completely ignored by the program:
Comments are extremely useful. Think of them as sticky notes you put in your notebook. The computer does not read them, but you will appreciate them when you come back to your code a week later and cannot remember what you were trying to do.
A good habit is to write short and clear comments. You do not need to comment every line, just the parts that might be confusing.
Python is a programming language created by Guido van Rossum, easy to read and extremely versatile. The print() function lets you display text and numbers on screen. Comments start with # and are ignored by the program. You use them as notes to yourself.
Create the title screen for the game "Python Kingdom". Display the game title framed inside a border of # characters, with the subtitle "The Curse of Dark Bug" below it. Use print() for each line and add a comment explaining what the program does.
# Display the game title screen
DISPLAY a line of # (top border)
DISPLAY "#" + spaces + "#" (empty line in frame)
DISPLAY "#" + "PYTHON KINGDOM" + "#" (centered title)
DISPLAY "#" + "The Curse of Dark Bug" + "#" (subtitle)
DISPLAY "#" + spaces + "#" (empty line in frame)
DISPLAY a line of # (bottom border)The game's hero needs to introduce themselves. Use print() and concatenation with + to display a welcome message. The program must display: "Welcome, traveler!", then on the next line "You are the last hero of Python Kingdom." and on the third line "Your mission: defeat Dark Bug!". Use concatenation for at least one line.
# The hero's introduction message
DISPLAY "Welcome, traveler!"
DISPLAY "You are the last hero of " + "Python Kingdom."
DISPLAY "Your mission: " + "defeat Dark Bug!"Create an ASCII map of Python Kingdom showing 3 locations connected to each other: "Starting Village" in the center, "Shadow Forest" above, and "Bugged Castle" below. Connect them with lines using | and --- characters. Add a title "KINGDOM MAP" above the map and a comment explaining what the map represents.
# Draw the kingdom map with text characters
DISPLAY the map title
DISPLAY an empty line
DISPLAY "[Shadow Forest]" (top location)
DISPLAY "|" (vertical connection)
DISPLAY "[Starting Village] --- [Fire Mountains]" (center)
DISPLAY "|" (vertical connection)
DISPLAY "[Bugged Castle]" (bottom location)Create a narrative "loading screen" for the game. Display a text of 5-6 lines that briefly tells the legend of Python Kingdom: the kingdom was cursed by Dark Bug, a hero must traverse 9 lands and restore peace. End with the message "Your adventure begins now...". Add comments that separate the sections.
# The game story - narrative introduction
DISPLAY "It is said that Python Kingdom was"
DISPLAY "once a prosperous and peaceful land."
DISPLAY "But the dark Dark Bug has cast"
DISPLAY "a curse upon the entire kingdom."
DISPLAY empty line
DISPLAY "Only a brave hero can travel"
DISPLAY "through the 9 lands of the kingdom"
DISPLAY "and restore peace."
DISPLAY empty line
DISPLAY "Your adventure begins now..."Create a small program that displays a "business card" with your info: name, age, city, favorite hobby, and favorite school subject. Each piece of info must be on a separate line. Use concatenation with + for at least one of the lines.
# Digital business card
DISPLAY "Name: " + your name
DISPLAY "Age: " + your age
DISPLAY "City: " + your city
DISPLAY "Hobby: " + your hobby
DISPLAY "Favorite subject: " + your subjectWrite a program that displays a countdown from 5 to 1, followed by the message "Liftoff!". Each number must appear on its own line. Add a comment explaining what the program does.
# Countdown to launch
DISPLAY 5
DISPLAY 4
DISPLAY 3
DISPLAY 2
DISPLAY 1
DISPLAY "Liftoff!"Congratulations! You have created the first elements of the Python Kingdom game. Copy the code below into a .py file and run it to see the full title screen:
Check how well you understood the lesson with these 5 questions.