Python 201

A deeper look at Python for intermediate or advanced coders in upper middle or high school with a focus on real-world computing problems. Request Quote

Course Summary
  • Grades 8+
  • Advanced level
  • 15 lessons
  • Python
    • Web
Course Includes
  • 15 lessons
  • 129 activities
  • Enhanced Creativity Tools
  • Automatic Assessment
  • Tutorials and Reviews
  • Coding Puzzles
  • DIY Projects
  • Quizzes
  • Answer Keys
Prerequisites
No previous coding experience required.

Lesson Plan

Lesson: Data Types

Time: 40+ mins

Introduction

In this lesson, students are introduced to Python data types such as strings, numbers, and booleans.

Vocabulary

  • Data Type: A data type is a particular kind of data. The type of the data determines what operations or functions can be performed on that data. Different data types cannot be combined with each other without converting the data type. Strings, integers, floats, and booleans are examples of data types in Python.
  • String: A string is a sequence of characters (letters) enclosed in either double or single quotes. Strings can be stored as variables and perform different functions on the strings. Individual pieces of a string can be accessed using an index, where the first character is stored in index 0.
  • Concatenate: Joining two or more strings together to make one longer string. To concatenate strings, use a + symbol between the two strings. Concatenating strings creates a new string which contains all of the original strings.
  • Integer: An integer is a positive or negative whole number. Integers should not be enclosed in quotation marks. Integers should be treated just like numbers and can be used in mathematical calculations.
  • Floating Point Number (Float): A float is a number with decimal precision and is always displayed with a decimal point. When you combine floats and integers in a mathematical calculation, the resulting answer will always be a float.
  • Boolean: A boolean is a value that is either True or False. In Python, the T and F in true and false must be capitalized. Boolean values are often used to create branching logic in programs.

Objectives

Students will...
  • Define and use strings, integers, floats, and booleans
  • Identify the difference between the four data types
  • Apply coding concepts to convert strings to integers
  • Apply coding concepts to convert integers to strings

Materials

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

Warm-Up (5 minutes)

Ask students to draw a visual representation or describe one of the following similes:
  • A variable is like a container for information
  • A variable is like a labeled drawer that stores one item at a time.
  • A variable is like a name tag that is put on a value.
  • A variable is like an envelope that stores and labels a single value.
Suggested answer: A variable is like a container for information. The value on the right side of the equal sign (car = “Toyota”) gets stored into the named container on the left side of the equal sign.

Activities (35 minutes)

Facilitate as students complete the Data Types modules on their own:
1. Data Types (Tutorial)
    • Students will read a short document that explains the fundamental data types in Python.
    • Check that students are clicking the orange “play” buttons to instruct their computer to perform the given instruction.
    • Do students need help with the “string names” puzzle? Give a hint: Tell them to use the code in the "Strings" section as a reference.
    • Tell students to click the “Next” button (located at the bottom of the document) to move on to the next module.
2. Concatenation (Tutorial)
    • In this module, students will explore how the “+” operator concatenates two string by joining them.
    • Do students need help with the “concatenate words” puzzle? Give a hint: Tell them to use the code listed above as a reference.
3. Integers (Tutorial)
    • In this module, students will practice using integers in their code.
    • Ask students, “True or false: An integer is a positive or negative whole number.” (True)
    • Optional: Before students select the “play” button, ask them to write down what they think the code will output.
    • Tell students that the puzzle problem (titled “Add numbers”) is asking them to sum the total amount of money--not the total number of coins.
4. Floats (Tutorial)
    • In this module, students will learn about floats and practice combining floats with integers.
    • Optional: Can your students think of other situations when a computer should use a floating point number?
5. Booleans (Tutorial)
    • Students are introduced to Python boolean values, which must be capitalized as either “True” or “False.”
    • Optional: Can your students think of another situation that a computer might represent with a boolean value?
6. Type Error (Tutorial)
    • Emphasize to students that in Python, values that are different data types cannot be combined with the “+” operator.
    • In this module, students will need to identify the error.
7. Str Function (Tutorial)
    • In this module, students will expand on functions and learn about the str function which produces the string version of its argument.
    • Do students need help with the “Tonight’s reading” puzzle? Give a hint: Tell them to use the code listed above as a reference.
    • Do students need another hint? Tell them that there is one space after the word “page.” Also tell them there is one space before and one space after the word “to.”
8. Int Function (Tutorial)
    • This module contains two puzzles: “Age Difference” and “Input Sum.”
    • In this module, students will learn how the int function produces an integer from its arguments.
    • Optional: Before students select the “play” button, ask them to write down what they think the code will output.
9. Quiz
    • In this quiz, students will solve 5 different data type puzzles.
    • In each problem, students will be given certain variables containing integers and strings. They will need to combine their values to produce the expected result.
    • Note: Students may have to convert integers to strings and vice versa with the “str” and “int” functions.

Discussion Questions/Follow-Up Activities (20 minutes)

Review the following with your students:
    • Why should a computer use a floating point number when a self-driving car is calculating what angle to turn the steering wheel? (for higher precision and higher accuracy)
    • What is one thing you learned today about boolean values? (In Python, boolean values must be capitalized as either True or False.)
    • What is a string? (A string is a sequence of characters) Who can give an example of a string? (A word, phrase, or story that is enclosed in a pair of quotation marks)

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-17, 3A-AP-17, 3B-AP-11
  • CS CA: 6-8.AP.11, 6-8.AP.13, 6-8.AP.17, 9-12.AP.12, 9-12.AP.16
  • ISTE: 1.c, 1.d, 4.d, 5.c, 5.d