Skip to content

Aug 23: I/O, Variables, Assignment

Learning Objectives

After today's class, you should be able to:

  • Explain differences between a program's code and output.
  • Use a Python shell to execute input and output functions.
  • Write assignment statements and use assigned variables.

Lesson Outline

Announcements [5 min]

  • Wk01 assignment – see the explanation on Canvas
  • Get started on Chapter 1 and Homework 1 (links below)
    • No TA hours on Sunday 8/25; the TAs have training
    • I generally don't give help during the weekend hours

POGIL Activity [45 min]

  • Introduction to Python – see example code below
    • If you are absent today, complete this activity at home
    • Bring your completed activity to class or office hours
  • Optional: To learn more about POGIL, check out pogil.org

Your To-Do List

By the end of today

Due Tuesday at 11pm

Example Code

Model 1 – copy into the editor, save as hello.py

# display a welcome message
print("Welcome to Python 3!")

# give the user a compliment
name = input("What's your name? ")
print(name, "is a great name!")

Model 2 – copy one line at a time into the shell

input("enter the mass in grams: ")
mass = input("enter another mass in grams: ")
mass
unit = input("enter the units for mass: ")
print(mass, unit)
print(mass / 2)
ten = 10
print(ten / 2)
abs(-1)
abs(-1 * ten)

Model 3 – copy one line at a time into the shell

data = 12
data
Data
Data = 34
data
Data
3data = "hello"
data3 = "world"
data3 = hello
hot = 273 + 100
273 + 100 = hot
hot
hot - 100