« Middle School Courses
This course is included with our Coding/STEAM Curriculum - Middle School Plan

Lesson Plan

Lesson: Variables and I/O

Time: 40+ mins

Introduction

In this lesson, students are introduced to variables and I/O (input/output). Additionally, students will learn to use variables to store and retrieve data in Python as they solve puzzles and fix syntax errors.

Vocabulary

  • Variable: Variables are used to store values at a named location in a computer's memory. Variables can have many types such as integers, strings, or booleans. To access the value in the variable, simply use the name of the variable and the name will be replaced with the value when the program is executed.
  • Variable Assignment: An instruction that assigns a value to a variable. For example, the instruction country = "USA" assigns the value "USA" to the variable country.
  • Reassigning Variables: Reassigning variables will remove the old value stored in the variable and replace it with the new value that is assigned to it.
  • Return Value: A value that a function outputs once the function has been run. This value can be stored in a variable or used in another calculation.

Objectives

Students will...
  • Use variables to store information
  • Initialize a variable
  • Reassign values to variables
  • Use the results of functions in their code
  • Request user input and respond using the input

Materials

  • Computers (1 per student) with student account access to Tynker.com

Warm-Up (5 minutes)

Ask students to answer these short-response questions:
  • What would someone find challenging about learning Python (e.g., syntax, variables, functions)? What advice would you give them (e.g., if you run into an error, check that you properly indented your code)?

Activities (35 minutes)

Facilitate as students complete the Variables and I/O modules on their own:
1. Variables (Tutorial)
    • Students will read a short document that explains variables.
    • Check that students are clicking the orange “play” buttons to instruct their computer to perform the given instruction.
    • Do students need help with the puzzle? Give a hint: Tell them to assign an integer to an age variable.
    • Tell students to click the “Next” button (located at the bottom of the document) to move on to the next module.
2. Naming Variables (Tutorial)
    • In this module, students will need to apply syntax knowledge to fix the syntax errors.
    • Note: Students are provided information on how to fix the syntax error (e.g., remove spaces from the variable “awesome sauce”).
3. Using Variables (Tutorial)
    • In this module, students will practice changing the values in a variable’s name and action to alter the output.
    • Optional: Before students select the “play” button, ask them to write down what they think the code will output.
4. Combining Values (Tutorial)
    • In this module, students will practice combining values.
    • “Print a sentence” puzzle bonus: Ask students to print a different sentence using three different variables. Here is an example of what their code might look like:

5. The Input Function (Tutorial)
    • Students are introduced to the input function, which asks the user for a value and returns the result.
    • Check that students are exploring the interactive activities and clicking the orange “play” button.
6. Multiple Assignments (Tutorial)
    • In this module, students will practice assigning multiple variables a value.
    • Optional: Before students select the “play” button, ask them to write down what they think the code will output.
    • Are students struggling with the puzzle titled “Sum both ways?” Give a hint: Tell them to use "a + b" as the value for both "a" and "b" in a multiple assignment instructions: a, b = a + b, a + b.
7. Quiz
    • Students will be asked 4 quiz questions to review concepts from this lesson.
    • Quiz questions involve using variables to store information, using multiple assignments, printing translations, and analyzing the final value stored in a given variable.

Discussion Questions/Follow-Up Activities (20 minutes)

Review the following with your students:
    • True or false: A variable name cannot have spaces. (True)
    • True or false: A variable name can start with a number (e.g., “3”). (False)
    • True or false: You can join multiple variables with strings. (True)
    • True or false: It is impossible to combine variables. (False)
Bonus: Ask students to create their own true/false questions and quiz a neighbor.

US Standards

  • CCSS-ELA: SL.8.1, RI.9-10.3, RI.9-10.6, RI.11-12.3, RI.11-12.6, L.9-10.3, L.9-10.6, L.11-12.3, L.11-12.6
  • CCSS-Math: HSN.Q.A.1, HSN.Q.A.2, HSN.Q.A.3, MP.1, MP.2, MP.4
  • CSTA: 2-AP-11, 2-AP-13, 2-AP-16, 2-AP-17, 3A-AP-17, 3B-AP-11
  • CS CA: 6-8.AP.11, 6-8.AP.13, 6-8.AP.16, 6-8.AP.17, 9-12.AP.12, 9-12.AP.16
  • ISTE: 1.c, 1.d, 4.d, 5.c, 5.d, 6.b
This course is not part of your plan. Please upgrade to view all answer keys

Class Presentations

These student-facing slide presentations help educators seamlessly run Tynker lessons in a virtual or physical classroom setting. Each lesson has its own set of slides that introduce the big ideas, suggest unplugged activities, and include a section for each activity module. While running lesson slides, you can switch back and forth between the activity, the slides, answer keys and other lesson materials.
A sample slide presentation is available for your review. Please log in to view all the class presentations available with your plan..
Lesson 1
Welcome to Python
32 Slides
Lesson 2
Variables and I/O
29 Slides
Lesson 3
Data Types
29 Slides
Lesson 4
Math Operators
32 Slides
Lesson 5
Boolean Logic
35 Slides
Lesson 6
Turtle Graphics
31 Slides
Lesson 7
Branching
27 Slides
Lesson 8
While Loops
27 Slides
Lesson 9
Strings
32 Slides
Lesson 10
Lists
28 Slides
Lesson 11
For Loops
24 Slides
Lesson 12
Functions
28 Slides
Lesson 13
Dictionaries
20 Slides
Lesson 14
Classes and Objects
24 Slides
Lesson 15
Recursion
20 Slides