Everyone can learn to code; it’s just like solving a puzzle or a riddle. You apply logic, try a solution, experiment a little more, and then solve the problem.
Why should Kids Learn to Code?
There are many great reasons to learn computer programming, but here are my top two:
- Coding is fun.
- Coding is a valuable job skill.
Have your children wanted to build their own level for their favorite video game? Coders do that! What about create their own phone app? They can bring that idea to life by programming it on a computer!
Coding is the skill of the 21st century. Jobs today require more problem-solving ability than ever before, and more and more careers involve technology as an integral requirement.
Coding = solving Problems
the concepts it introduces are a great pathway to a rewarding, inspiring pastime and better career opportunities. People who can program—and thus solve problems quickly and effectively—are highly valued in today’s world, and they get to do interesting, fulfilling work.
Python Basics
Computer programming, or coding, is how we tell a computer to perform a task, and understanding how to code puts the power of computers at your fingertips.
import turtle
colors=['red', 'purple', 'blue', 'green', 'yellow', 'orange']
t = turtle.Pen()
turtle.bgcolor('black')
for x in range(360):
t.pencolor(colors[x%6])
t.width(x/100+1)
t.forward(x)
t.left(59)
Getting Started
To begin coding, we have to speak the computer’s language. Computers need step-by-step instructions, and they can only understand certain languages. Just like a person from Russia might not be able to understand English, computers only understand languages made for them.
Computer code is written in program- ming languages like Python, C++, Ruby, or JavaScript. These languages allow us to “talk” to our computer and give it com- mands. Think about when you teach a dog to do tricks—when you give the “sit” command, he sits; when you say “speak,” he barks. The dog understands those simple commands, but not much else
you say.
Likewise, computers have their own limitations, but they can do whatever you tell them to do in their language. To get you started using Python on your computer, we’ll go through these three steps together:
- Download Python.
- Install Python on your computer.
- Test Python with a simple program or two.
Writing Programs in Python
In the new, blank window, type the following three lines of code:
# YourName.py
name = input("What is your name?\n")
print("Hi, ", name)
The first line is called a comment. Comments, which begin with a hash mark (#
), are programming notes or reminders that the computer ignores. In this example, the comment is just a note to remind us of the program’s name. The second line asks the user to input their name and remembers it as name. The third line prints “Hi, “ followed by the user’s name. Notice that there’s a comma (,) separating the quoted text “Hi, “ from the name.
Running Programs in Python
When you save the file and run it, you’ll see your Python shell window start the program by showing the question What is your name?. Type your name on the next line and press enter. The program will print Hi, followed by the name you typed. Since this is all that you asked your program to do, the program will end, and you’ll see the >>>
prompt again.
Summary
Learning to code is like learning to solve puzzles, riddles, or brainteasers. You start with a problem, apply what you know, and learn new things along the way. By the time you finish, you’ve exercised your mind, and you’ve answered a question. Hopefully, you’ve also had fun.
At this point, you should . . .
- Have a fully functional Python programming environment and text editor.
- Be able to enter programming commands directly into the Python shell.
- Be able to write, save, run, and modify short programs in IDLE.
- Be ready to try more advanced, fun programs