As if coding wasn’t intimidating enough, now kids and parents have to battle something called Python just to be able to learn one of the fastest-growing programming languages available?
I assure you, it’s not nearly as frightening as it sounds!
Why is Python good for kids?
In fact, Python is actually known for having syntax that’s simpler and easier to write than many other kids coding languages including Java coding and C++. Meaning, Python is a programming language that uses less punctuation and is easier to read, which makes it a great option among the best coding classes for kids.
(Python's creator, Guido van Rossum was an employee at Google, and he named the language after the comedy troupe Monty Python's Flying Circus, not the reptile. Read more about coding vocabulary.)
The pictures to the right show what some other programming languages require just to print "Hello World!" As you can see, these languages require a lot more than just one print statement (more on print statements below).
To show just how clear the syntax can be, consider these definitions and examples.
Variables are used to store information, so kids can think of variables like boxes they can store items in.
Example: And in order to remember what was put in the box, they assign a descriptive name, like:
In this case, kids now have the means to remember how many doughnuts will go in the box once that box is filled, which leads us to...
After a variable is given a name, you give it a value. Assigning this value is like filling the box.
Example: if kids had 3 doughnuts, they would set number_of_doughnuts equal to 3, like so:
number_of_doughnuts = 3
Assigning this value of “3” to the variable is called initializing.
For kids to be able to see the value of their variable when they run their program, they’ll need to print it. (No, it won't send anything to the printer!). There will be more on printing below, but for now, the process would simply look like:
Variables can hold data besides just numbers; they can hold words as well. Programmers call word variables “strings.”
Example: So if your kids named one of their boxed doughnuts, what would it be?
doughnut_name = "Doughy"
As you can see, when creating string variables, their value must be inside quotation marks.
You can also use variables to show if something is true or false. This type of data is called a boolean.
Example: So, you’d create a variable in this case in order to indicate whether doughnuts exist.
doughnuts_exist = True
You can also set it to be not true, as would be the case if your kid ate the doughnut and thus the doughnut wasn't there anymore.
It's as simple as change the variable to the following:
doughnuts_exist = False
To put it all together:
Kids would use variables to store different types of data that they can use later in their programs:
string_variable = "value"
number_variable = 3
boolean_variable -= True
Making a print statement
To get the output from the program, kids would use the print statement, which includes a few different procedures.
For example, kids would start by typing the word: print
After that, they'd type an opening parentheses and an opening quotation mark: print("
Then they'd write any text they want displayed: print("What? I can write anything?!
When the text is finished, they put a second quotation mark and a closing parentheses: print("What? I can write anything?!")
Once executed, the output would simply be: What? I can write anything?!
You can also use print statements to do simple math, for instance:
print(4 + 5)
print(10 - 2)
print(3 + 1 - 4)
What prints to the screen? The answers to the equations (9, 8, etc.).
A conditional statement helps direct the flow of a program. It does this by having some portions of the code only run under specific scenarios.
Specifically, conditional statements evaluate to either true or false, and this value determines if a specific piece of code will run.
Conditionals always use the keywords if, else, and elif (short for "else if").
For example, if your child is making a game and their player has full health or life, what should happen when that player gets hit?
To start, they’d make a variable for life and then set it equal to 3:
life = 3
Then, if the player gets hit, the player will lose life, or a life point. To subtract from life, they'd simply say:
life -= 1
The life variable is then printed:
And code is run to see the result!
(If the above is confusing, “life -=1” is just shorthand for life = life -1, which sets life to one less then what it was before. You can write either version, depending on preference.)
To go one step further, you can only subtract so much life, right? Meaning, a player’s life doesn’t typically drop below zero. So, a condition would need to be used to prevent that scenario.
An if statement specifically would be used to prevent life from dropping under zero.
if life > 0:
life -= 1
Here, if statements will run the code indented beneath them only when the condition after them is true. So, only when life is greater than zero will life -=1 be executed.
Use an elif statement to do something when the first if statement isn't true, but you want to check for another condition.
elif life == 0:
print("The player ran out of life!")
Note the difference between “=” mentioned earlier and “==” here; life = 3 and life == 3 are very different!
Write life = 3 when you're assigning a value to the variable life: "Life has the value 3."
Write life == 3 in conditional statements: "Is life equal to 3?"
Additionally, kids would use an else statement to do something when the if and elif statements aren't true. This statement has no conditions, so it will catch anything that isn't covered by the previous statements.
In programming, loops allow you to repeat a block of code a number of times. While loops, then, repeat code until a specific condition is met.
For example, maybe there's a question like the one to the right—how many leaves does the tree have?
Well, how many tries will it take to guess?
1 guess? 2 guesses? 4 guesses? 100 guesses?
For times when a block of code needs to run an uncertain or non-specific amount of times, you use a while loop.
While loops are made of a loop control variable (made first), a conditional statement (the conditions that must be met for the loop to run), and a loop body (the actual code that will run).
On the other hand, for loops are used to repeat a block of code if you know how many times it needs to run. For loops help you perform an action on multiple elements, if you know how many there are.
There are many times where you'd want to perform a series of actions, and instead of writing those statements over and over every time, you can use a function!
Pretty straightforward, right?
Learning with PyCharm
All of this above might be good and dandy, but how and where do kids actually write code like the examples above to create programs?
An IDE, or Integrated Development Environment like PyCharm allows for just that. Just as you’d expect from other programs, PyCharm allows for the creation and organization by project in order to keep files together in one folder.
Interpreters allow computers to break down and understand programming languages like Python, similar to dictionaries.
When a program is run, kids will see a new console window appear at the bottom of PyCharm that houses and displays the output of the program!
It’s no secret anymore that coding makes for a good career, being that it’s one of the most in-demand job skills in today’s market.
And to make it an all around great career, coding jobs pay well, and the work of a coder is extremely visible across a number of industries. From cryptography, artificial intelligence, machine learning, and much more, Python has a number of cool and relevant applications you might not have ever really thought of.
For kids wanting to jump in right now with the help of an iD Certified Instructor, they can do so either one-on-one in an online coding class or with a Python tutor online, specifically, or even with a small group of other like-minded coders in our online after-school programs.