Variables and I/O

Store values in named locations in a computer's memory.

Grades 8+
  • Web
Request Quote
for Middle School Curriculum

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 are 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
Variables and I/O
Python 201
Lesson Includes
  • 7 Activities
  • 1 Completion Badge
Languages
Python
Experience
Advanced