Tag Archives: coding

Python Variables and Offline Coding Exercise

Young programmers need to understand the purpose of Python variables. In a program, variables store values that can change. They are very powerful. They can be used to count, create lists, store user input, report information, personalize the user experience, trigger an action, calculate amounts, and more!

One of the best ways to learn about computer science concepts is hands-on learning. In other words, writing programs that use variables. Talking about variables will generate a limited understanding. Having said that, before jumping into Python programming, it is worthwhile to begin instruction about variables with an offline coding exercise.

Variables can seem a bit abstract to a child. It is worthwhile to make the concept tangible. A quick activity that connects variables to daily life will help elementary and middle school students to form an understanding of their use.

Have your students apply computational thinking to think about the world around them as a set of variables that store and direct events. This knowledge can then be transferred to programming activities. Refer to the connections below as a way to create an offline coding exercise about Python variables.

The Value of a Variable Changes

Just like the weather, a variable is a value that changes. It could be sunny in the morning and then rainy in the afternoon. What is the weather?

Complete the value of the variable weather. For example: weather="sunny"
weather="   "

A Variable Stores Different Types of Information

A variable can be text, a number, or a list. In the above example, the value stored was a word. However, you can also store numbers as variables. Temperature is a numbered variable that changes. It could be 5°C (41°F) at night and then 15°C (59°F) in the afternoon.

Write the value of the variable temperature. For example: temperature="15"
temperature="   "

The Value of a Variable Can Trigger an Event

The value of a variable can cause an action to occur. For example, if it is hot outside you might wear shorts. Or if it is rainy you might use an umbrella.

Complete the script using weather as the variable. What will you wear?

if weather=="snowy":
    what will you wear?

An Event Can Trigger the Value of a Variable to Change

When a program starts, a variable has a specific value. However, an event may occur that changes the value. This event could make a number higher or lower. Or, it could assign a new word to a text variable.

When making a decision you might change your mind depending on what is happening. Programs do the same thing! Pretend you are getting dressed for school. What piece of clothing do you want to wear?

Complete the value of the variable clothing
clothing="   "

The item is in the laundry. What piece of clothing will you wear now?
clothing="   "

A Variable Is Stored in a Numbered Location

The value of a variable is saved in a spot that is like a numbered storage bin. When the program needs the value in the variable it takes it from the bin. The computer knows where to find the value because it has a unique location.

Labeling a location to store things is done everyday at school. For example, your school locker may have a number. Or the library may have a numbered bin of books.

Look around your classroom. What bins are used to store things? Are they labelled?

Write your discovery as a variable. For example: mylocker="1215" or period1bin="homework"

bin="item"

A Variable Is an Efficient Way to Refer to Information

A variable is like a container that stores information. The label on the outside is the name. The item you put inside is the value. When giving an instruction, the program uses the variable name, not the data stored in it. This is done to save time and keep things simple.

Imagine it is recess time. The teacher needs to tell the students what to do. The teacher gives the instruction, “Please go and get your snack”. The teacher does not say, “Please go and get your apple, crackers, cookies, carrots, chips, or banana.”

The word “snack” is used to refer to many values. It also allows the values to be unknown. The teacher cannot know what you or your classmates brought for a snack. Using one word that is meaningful is an efficient way to refer to information.

People often use one word to quickly refer to many things. Turn the word lunch into a variable. What is in your lunch today? Make a list of the values in your lunch. For example:

lunch=("orange juice", "ham sandwich", "apple", "blueberry muffin")

lunch=

A Variable Can Store User Information

Sometimes the programmer assigns the value of a variable. Other times, the user inputs a value. This can be done by prompting the user to enter data by displaying a text box or question on the screen. The program can then use this information to sign into an account, customize the settings of an app, or pick a selection.

Think about a game you play on a device. What information does it ask you to input? Each of the pieces of information is a variable.

List two pieces of information you must enter into a game before you could play it. For example:

playername="technokid"

playermode="single player"

Python Variables and Fun Programming Activities for Kids

If you are looking for some fun programming activities for kids that use variables, take a look at TechnoTurtle. This STEM project introduces beginners to Python variables in a way that is easy to understand. Students develop programs that have players play Mad Libs, a Carnival Game, and a Guess the Number Game. Each uses variables to trigger action. These coding activities are a great way to make Python variables meaningful to kids. The lessons provide a foundation for further learning.

Python variables and TechnoTurtle

Teach children about Python variables using the STEM project TechnoTurtle.

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.

Design a Coding Unit for the Classroom

STEM learning objectives are being included in many school, district, and national curriculum standards. As a result, educators are challenged with creating engaging and challenging instructional materials to teach computer science skills. But most teachers don’t have a technology background, much less knowledge of programming. Here’s some help. Whether you’re using ScratchJr, Scratch, HTML and CSS, or Python and the Turtle Library, the activities will be similar. Following are some basic strategies to consider when you start to design a coding unit for the classroom.

Practice Sequencing Algorithms Offline

Design a coding unit to include offline exercises. This will develop computational thinking. A starting point for instruction is to build algorithms. An algortithm is a description of the program. It uses words and symbols to sequence the instructions.

The logical order of coded instructions is critical. To build this skill, instruct students to physically act out and order a list of directions in simple, everyday language first. For example, if a programmer had to write a program for the task of putting a piece of paper into the trash, it may have the steps:

design a coding unit

Have students act out the steps they listed to check them. Or, have a list of mixed up steps that students must unscramble to place them in the correct order.

Start Simple

When you design a coding unit, move from simple to more complex code slowly.

Don’t offer a complete set of instructions in code and have the students copy it and run it to see the result. This may intimidate young programmers and even make them think that coding is too difficult. Moreover, they won’t learn what each part of the code does.

Instead, write a few lines. Then test the result. The instant response will create a connection between the coding and its function.

coding for kids

In TechnoWhiz, primary students are introduced to ScratchJr by using one block at a time to move the character on the stage. They observe the resulting motion. Then they combine a series of blocks to create a script and see the effect. Next, they add more characters and move them, and learn to loop their actions. By the end of the project, they are able to make an interactive, one-of-a-kind racing game with a background, formatted text, and characters moving at different speeds, dancing, and talking!

Use Trial and Error

Invite students to experiment with values to figure out what works. Try a number or value. Does it need to be higher or lower? Test often to see what works.

Encourage exploration. For example, when using Python and the Turtle Library, circle(50) draws a circle with a specific size. Students can explore by changing the number to a higher value and a lower one. Or code left(90) to turn the turtle symbol. Then change the value to see what angles the turtle turns. The repeated experimentation will result in learning that can be applied in subsequent activities.

Teach Debugging

Don’t wait until mistakes are made. Early in the project, create errors with intention. Have students ‘break‘ the script, then fix it. As a result, they will recognize mistakes that may be made later in their own programming and be more likely to correct them independently.

design a coding unit

Apply Skills

Introduce a skill, repeat or review it, and then transfer it to another application using the program. Avoid teaching a concept in isolation. When students re-use skills in different contexts, they will accumulate their knowledge and be able to apply it in their own creative projects.

teaching coding to kids

For example, in TechnoTurtle students learn to use Python to control the movement of a turtle symbol. Then they apply their skills to write scripts to draw pictures and to move the turtle through a maze. In other parts of the project, they learn about variables. Then they use this concept to create Mad Libs and to produce an interactive carnival game.

Show Samples

Demonstrate how a completed project might look at the beginning of a lesson. This will serve multiple purposes: students will have a clear idea of what they’re making, they will be inspired to create their own unique version, and the sample can be a coding reference guide to use if trouble shooting is needed.

In TechnoHTML, a sample web page about skateboarding sparks student interest and demonstrates the skills they will learn using HTML and CSS:

design a coding unit

  • Formatting text
  • Adding images
  • Making lists
  • Linking to sites

Provide an Opportunity to Share

At the completion of the project, ensure that students have an authentic audience. This helps students to connect their work in the classroom to the real world and see a purpose for their efforts. Their peers are a perfect audience. Celebrate the finished projects and encourage interaction and feedback. The digital nature of programming projects makes it easier than ever to share work with classmates, family, and friends.

design a coding unit

For example, in TechnoCode, middle school students place their collection of completed animated scenes, stories, mazes, and games into an Activity Studio to share with others.

Then they invite feedback and recommendations for improvements.

Reflect on Learning

Finally, give students an opportunity to reflect on their experiences in learning to code. In either written form in a journal or as a class discussion, ask:

  1. What did you like about learning to program?
  2. Is there anything in your project that you would like to change?
  3. What do you wish you knew how to do?
  4. Have you learned anything about yourself?
  5. What advice would you give to a beginner programmer?

design a coding unit

In TechnoTales, students in grades 2 to 5 use five simple reflection responses to gain some insight into their learning.

The young programmers used Scratch to design a story with four scenes, multiple animated characters, a plot with a dilemma to solve, and a happy ending!

Design a Coding Unit

TechnoKids has elementary and middle school programming projects for Scratch Jr, Scratch, Python and the Turtle Library, and HTML. Before starting to design a coding unit of your own, try one! Visit the TechnoKids online store.

design a coding unit

TechnoKids has programming projects to teach ScratchJr, Scratch, Python, and HTML and CSS

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.