Tag Archives: python

Variables in Python and Teaching Coding to Kids

Variables in Python are used by programmers to store values. These values complete a task within a program. In game design variables can track scores, count the number of turns, or store player answers. However, they have many other uses. When teaching coding to kids, it is important that the purpose of a variable is understood.

variables in python

Variables in Python store values that a program uses to complete a task.

What Are Variables in Python?

A variable stores a value that can change. It is saved in a special spot that is like a numbered storage bin. When the program needs the value in the variable it takes it from the bin.

A variable can store lots of different types of information. For example, the value could be a number, text, or a list of items. In programming, a number is called an integer or int for short. Text is called a string or str for short.

A variable has two parts – name and value. To create a variable, you write the variable name, then an = symbol, followed by the variable value. For example: player=”Alex”

variable name and value

A variable has two parts – name and value.

Variables in Python Must Have Meaningful Names

Naming a variable is a fundamental skill. A programmer should be able to read the variable name and understand its use within the program. It is very important that it is short but concise. It’s name should describe its purpose.

A Python variable must:

  • be meaningful
  • be one word
  • have no spaces
  • use no symbols
  • not be a reserved Python word

Why Use a Variable?

Variables make a program flexible. Programmers use them for many reasons.

Variables Can Count the Number of Times an Event Occurs

Variables can count. This is useful when making a timer or tracking a player’s score. To count, you can create a variable called count=0. Each time the line of code count=count+1 is run than the value of the variable goes up by one.

Variables Can Store Multiple Values as a List

Variables can store more than one value. The list may look like this: pickcolor=(“red”, “blue”, “green”). By assigning multiple values to a variable it allows a program to make a choice. This use of variables creates games that are fun to play because the selection is unknown.

Variables Allow the User to Input Information

Sometimes the programmer assigns the value of a variable. Other times, the user inputs a value. This is done by prompting the user to enter data by displaying a text box or question on the screen. For example, the following code will store a user’s name:
name=input(“What is your name?”)

Variables Report Information

By using the variable name in a sentence you can report important information to the user. For instance, to display a player’s score the following code will join text with the variable value:
print(“The game is over. Your score is ” +str(score)).

Variables Personalize the User’s Experience

Variables can be used to communicate, making a device seem more human or less machine-like. Suppose that a player types in their name. Lines of code can have the computer give a personal greeting, such as Hello Sara. The sentence and variable are put together using this Python code: print(“Hello ” +str(player)).

Variables Can Trigger an Action

A variable’s value can change. If it is a number, it can get higher or lower. If it is a text, it could have another value assigned to it. Conditional logic can be used to trigger an action when a variable meets a specific condition. The value of the variable might need to be equal to, greater than, less than, or does not equal. When the variable value matches the condition, then an action will occur. The code might start like this if guess==”answer”:

Variables Calculate Amounts

Variables can be used in mathematical formulas. This has many practical applications. For example, a business owner can track employee earnings. The variables wage, hours_worked, and earnings can be placed into the formula earnings=wage*hours_worked.

Create Artwork and Build Games using Variables in Python to Teach Coding

Learning how to use variables in Python can be fun. In TechnoTurtle, the programming activities gradually introduce elementary and middle school students to variables. In this project they use variables to count loops and create spirographs that are random colors. As well, they store player answers to build a Mad Lib word game, a carnival game that awards a prize, and a guessing game. These programming tasks make the purpose of a variable easy to understand. Beginners experience first-hand how variables are used in a program to complete a task.

technoturtle and variables

Learning about variables can be fun.

Tips for Teaching Coding to Kids

Teaching coding to kids is more than just giving them lines of code to copy and then run. We want to empower students to become critical thinkers and innovative programmers. To build programming skills, beginners need to be provided with a variety of analytical and engaging experiences. To do that, we should spark their enthusiasm with a collection of activities that ensure success and an understanding of essential coding concepts. As they learn how to code original creations, students will become keen, competent programmers. They will have the foundational STEM skills for the workplace of the future.

tips for teaching coding

Here are some suggested types of activities to consider when teaching coding to kids.

Explore and Investigate

Teach code a line at a time. Then ask students to analyze and experiment with the code. Explore with different values and see the outcome. What happens with a higher or lower number? When the line of code is moved to a different place, what happens? What happens when a character is omitted? This strategy builds student insight into the meaning of the code so much better than just asking them to copy a given set of instructions and then running them.

Guess and Check

Provide completed code and ask your students to be detectives. By reading the lines of code, comments, or scanning for words they recognize, they can try to infer what the code will do. Then run the code and see if their guesses were accurate. This makes students keen observers and critical thinkers.

Use Templates to Jump Start Learning

Young programmers have the ability to understand the code, but don’t always have the keyboarding skills needed to type many lines of code accurately. When introducing specific coding concepts, consider giving the students templates with parts of the code already written. The students just add code to make the desired result.

Teach Debugging Early

Don’t wait until errors occur and students are frustrated with the inability to correct them. Near the beginning of the coding unit, have the students generate specific errors to break the code. Have them see the resulting problem. Then fix it. As a result, students will become familiar with common mistakes such as omitting characters, mistyping, or placing code in the wrong order. They will recognize errors and know how to correct them.

Provide Samples to Spark Inspiration

Before starting a new project, inspire students by showing them a completed sampler. The goal is to ignite their interest but not to provide a set of instructions for them to copy. The code becomes a guide for students. They can use it as a starting point or to compare their work for troubleshooting. The sampler becomes the foundation for students to produce their own original projects.

Offer Support References

Online programming reference lists and libraries are usually so complete and exhaustive that they are ominous for kids to use. Instead, build a list of basic commands that will be used in the project and have it handy for the class to use and check.

Present Opportunities for Extra Challenges

Differentiated learning studies have shown us that students build skills in a highly diverse way. When teaching coding to kids, they are certain to progress at different rates. Students who struggle need support, repetition, and review activities to grasp coding skills. Some students will ‘get’ the concepts quickly and be ready for new ways to apply and extend their learning. Be prepared for these young experts with optional challenges to keep them excited and involved.

Reflect on Learning

During, and definitely after the end of the project, provide an opportunity for students to think about their coding experience. Write a journal entry. Ask questions such as: What was your favorite part of the program? What was the hardest part of learning to program? Which skills would you like to learn next? What advice would you give to a person learning how to use this program?

Teaching Coding to Kids Using TechnoTurtle

teaching coding to kids

TechnoTurtle, a new project by TechnoKids Inc., is an introduction to Python coding for beginners. It is designed for elementary and middle school students to learn basic programming skills. The fun activities include building a maze, creating artwork and spirographs, and inventing interactive games. TechnoTurtle incorporates all the above strategies to inspire young programmers to acquire fundamental technology expertise.

Teach Python Using the Turtle Library

Teach Python using the Turtle Library to ignite an interest in STEM. Python is a popular text-based programming language. It is used every day by programmers.

The Turtle Library is a collection of functions used to control a robotic Turtle. The commands can be combined with Python to build programs that create stunning artwork and original games. The use of the The Turtle Library is a fun way to introduce students to programming.

You may think that using the Turtle Library to teach Python is a waste of time. Shouldn’t students be learning ‘real code’ instead of functions that they won’t use in the workplace? How useful is it for young programmers to move a Turtle through a maze using forward(100) or draw using pendown()? The answer is….very useful!!!

The skills acquired from building programs using Python and the Turtle Library provide a foundation for further learning. By knowing the basics, young programmers can extend their knowledge to more complicated tasks in the future. Discover the 7 reasons you will want to use the Turtle Library with your students.

7 Reasons to Teach Python Using the Turtle Library

1. Produce a Wide Range of Coding Projects

The use of the Turtle Library is not limited to moving a Turtle around the canvas or making artwork. Although this is really fun to do, it can be used for so much more! Want to hook students’ interest in STEM? Then teach Python using the Turtle Library. Consider programming these games using the Turtle Library:

  • Etch-a-Sketch: Invent a drawing game that uses arrow keys to draw lines to create artwork.
  • Carnival Game: Design a game using conditional logic that awards a prize to players based on the option they pick.
  • Mad Lib: Create a word game that stores players’ answers as variables to form silly sentences.
  • Guess the Number: Combine the Random Library with the Turtle Library to build a game that has players pick a number between 1 and 10. Will they guess correctly?

2. Develop the Computational Thinking Skills to Sequence Instructions

Programming requires each line of code to be in the correct order to achieve a goal. When writing code with the Turtle Library of commands, students must apply computational thinking to determine what comes first, second, and third. This ability to sequence instructions will be helpful later when programs are longer and more complex.

3. Effectively Apply Debugging Strategies

No matter whether a programmer is using Python or has code that includes commands from the Turtle Library, the errors are the same. Mistakes in coding generate the identical name and syntax errors. For example, if a : (colon) is missing at the end of a loop, there will be an indent error. Understanding how to identify the problem and fix it is transferable to new programming tasks.

4. Understand How to Organize Scripts

No matter the programming language, programmers add comments to describe each section in a program. A comment is a brief description that acts as a summary. It explains the purpose of the code. Comments are used by programmers to communicate with others about the intent of the code. As well, they can act as markers to identify each part of a program. This makes it easier to locate a specific section for writing new code or debugging errors.

In Python a comment begins with a hashtag #. The symbol tells the interpreter to skip the line as it does not contain an instruction. For example, #store a word list is a useful descriptor that explains the purpose of the following lines of code. It is important for young programmers to get in the habit of using comments as it is good programming practice used by professionals.

5. Import Libraries to Build Programs

The Python programming language uses special words to tell the computer what to do. A function is a word that does a specific task by executing a stored set of instructions. Many Python functions are stored into libraries. Professional programmers use Python libraries to create responsive graphs, display the time, or grab information from a web page. The ability to import the Turtle Library is similar to importing any Python Library, making it a useful programming skill.

The ability to import libraries is an important reason to use the Turtle Library to teach programming skills. Programs that use the Turtle Library to create artwork and build games can include other Python libraries. For example, students can use the Random Library to pick a random number or item from a list. This is a fun way to make surprising geometric patterns or a Guess the Number game. As well, students can use the Time library to set the timing of events. This is very useful when flashing the word “WINNER” across the canvas in Carnival game. The programming skills that are introduced when using the Turtle library can be transferred to more complicated or work-related tasks in the future.

6. Appreciate the Importance of Accuracy When Writing Lines of Code

When students are writing programs using Python and the Turtle Library, they quickly learn the importance of accuracy. A reader can understand a story or report that has a few spelling or grammar mistakes. A computer cannot. If a program has a command spelled incorrectly it will not run. Moreover, if the code is missing a bracket, colon, or indent than an error will display. The emphasis on precision when coding is best taught early, as it is required by all programmers. Teach Python using the Turtle Library to support STEM.

7. Instant Feedback Develops Confidence

The Turtle canvas instantly shows the result of the code. This visual is helpful during program development. Nothing is more frustrating then trying to figure out why the code does not work the way it is supposed to when the program runs. Young programmers can quickly become frustrated. With a lack of immediate success, they can start to believe that they are not good at programming. Since the Turtle Library displays the output on a canvas, the programmer can see what they need to change to improve their program. For example, they might notice that the Turtle moves in the wrong direction, the pen needs be picked up to stop drawing a line, or the game title is too small to read. Seeing what needs to be fixed helps young programmers understand how to improve their code.

Support STEM. Teach Python using the Turtle Library. Spark an interest in programming.

TechnoTurtle Has Lessons to Create Artwork and Build Games

TechnoTurtle is a technology project, by TechnoKids Inc. that has lesson plans to teach Python using the Turtle Library. It has over 30 assignments that gradually introduce programming skills to elementary and middle school students. The instructions guide students to build programs, with additional open-ended challenges to spark creative exploration of code.

Introduce Beginners to Python Using the Turtle Library

Why not introduce beginners to Python using the Turtle Library? Python is a text-based programming language. To prepare elementary and middle school students to master this language, a good starting point is the Turtle Library. The Turtle Library is a collection of commands that can be used to create artwork and games.

What Is Python?

Python is a programming language created by Guido van Rossum about thirty years ago. His goal was to invent code that was easy to read, write, and understand. Today, Python is used by programmers to develop programs that:

  • analyze large amounts of data
  • build models to test ideas
  • find information on a website
  • host websites
  • design and launch mobile apps
  • support machine learning, which is when a device can improve how it works by itself

Python’s use by programmers is one of the reasons why teachers should introduce beginners to Python using the Turtle Library. It is important to hook student interest in programming in a fun way. The skills and knowledge they learn will provide a solid foundation for future learning.

What Is the Turtle Library?

The Python programming language uses special words to tell the computer what to do. A function is a word that does a specific task. Many Python functions are stored into libraries.

The Turtle Library is a set of commands that control a robotic Turtle making it move, draw, and write. When programming with Python, students must import the Turtle Library using the line of code: from turtle import *. This will then allow them to use all the commands from the Turtle Graphics Standard Library.

introduce beginners to python using the Turtle Library

The Turtle library has commands that control a robotic Turtle making it move, draw, and write.

5 Reasons to Introduce Beginners to Python Using the Turtle Library

1. Create Fun-Looking Programs that Excite Young Programmers

Python is a text-based programming language. The program output can be viewed in a Python Shell. However, the Python Shell only shows words. There are no graphics or animation. Instead, it is just plain text. This is not exciting to young programmers.

python shell

The Python Shell only shows words. There are no graphics or animation.

The Turtle Library of commands uses a canvas to show the program’s output. This invites creativity! Students can program a robotic Turtle to move around the screen to solve a maze. Programmers can create colorful artwork. Or, they can invent games for players. The possibilities are endless! The appeal to using the Turtle Library is that the program’s output looks fantastic – which is a great way to hook young programmers.

carnival game

Introduce Python in a fun way! Create colorful artwork or invent games using the Turtle Library.

2. Spark Creativity and Ignite an Interest in Programming

Kids are naturally drawn to making things. Whether it is painting, coloring, or writing they want to express their ideas and share their creations with others. Python programming combined with the Turtle Library invites artistic expression.

Students can design programs that draw pictures from lines, shapes, and symbols. In addition, by looping a set of instructions they can produce colorful spirographs or surprising geometric patterns. The ability to make things encourages students to enjoy programming.

create artwork

Use the Turtle library to spark creativity and ignite an interest in programming.

3. Code Make Sense

The first introduction to text-based programming should be fun. Typing line after line of code that looks like gibberish is not gratifying. Instead, you want students to feel empowered. The good news is that the Turtle Library of commands make sense.

The Turtle command names hint at what they do. For example, pensize(5) sets the thickness of the pen line; pencolor(“blue”) makes the outline color of the pen blue; and circle(20) draws a small circle.

The commands sequenced together make a simple program that draw a circle:

#draw a circle
from turtle import *
pensize(5)
pencolor(“blue”)
circle(20)

Imagine the possibilities! Since the Turtle Library of commands are understandable it makes programs easier to write and debug. Moreover, the simplicity provides a solid foundation for programming original creations. For example, students can extend their knowledge of drawing a circle to make a picture of a snowman, ant, or another object from circles.

draw snowman with Turtle Library

The simplicity of the code provides a solid foundation for programming original creations.

4. Only a Few Lines of Code Do A Lot!

Young programmers tend to have limited typing skills. This makes writing line after line of code tiresome – and boring. Moreover, it can cause a programming task to take exceedingly longer than the time allocated for instruction.

The great news is that by combining Python with the Turtle library, students can write fun programs in only a few lines. For example, they can have the computer respond to a player by displaying a personalized message in just 3 lines! The simple code will show a text box that has the player type in their name. A message will then display that says “Hello Player Name“.

from turtle import *
name=textinput(“Name”, “What is your name?”)
write(“Hello ” +str(name))

5. Illustrate Programming Concepts in a Meaningful Way

Programming concepts such as loops or variables can be so abstract that they are difficult for beginners to understand. However, blending Python with the Turtle Library makes them tangible. This is because the output on the canvas allows students to see what is happening.

For example, you can tell a student that a loop is a set of instructions that repeat. However, if they build a simple program that draws and counts circles on the Turtle canvas then suddenly
for shape in range(4): makes sense. They can watch four circles being drawn, forming a direct connection to how the code makes loops work.

from turtle import *
loop=0
for shape in range(4):
    circle(60)
    loop=loop+1
    write(loop)
    forward(50)

four looping circles

Count the circles to understand that loops repeat a set of instructions.

Introduce Beginners to Python Using the Turtle Library and TechnoTurtle

If you are looking for teaching ideas designed for elementary and middle school students check out TechnoTurtle. This project, published by TechnoKids Inc., has over 30 programming activities. Young programmers blend Python and the Turtle Library of commands to solve mazes, create artwork, and invent games.

python programming for kids_2

Introduce programming to beginners with Python and the Turtle library of commands.