August 29th: I/O, Variables, Assignment
Learning Objectives
After today's class, you should be able to:
- Explain differences between a program's code and output.
- Identify and execute Python functions for input and output.
- Write assignment statements and use assigned variables.
Lesson Outline¶
Announcements
- HW 1; due Wednesday by 11pm. Submit via canvas
Lecture
Submission Requirements
- Installing Thonny, flake8
- Comment Format
- Attribution statement
Fixing Code
- Download payroll.py and setup.cfg
- Using Thonny, run payroll.py first to see how it works
- Run
!flake8 payroll.py
in the shell- You should see several lines of output
payroll.py:4:18
means "Line 4, Char 18"
- Correct each issue, one by one, in the editor
- Rerun flake8 by pressing Up+Enter in the shell
Class Activity Using Thonny
-
Activity 1: copy the code below into Thonny, save as WelcomeName.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!")
-
Activity 2: copy one line at a time into the shell. Notice the result as you execute each line. If error message, read carefully. Work on correcting the errors.
input("enter the mass in grams: ") mass = input("enter another mass in grams: ") mass unit = input("enter the units for mass: ") ten = 10 print(ten / 2) print(mass, unit) print(mass / 2) abs(-1) abs(-1 * ten) abs(-1 + 5)
-
Activity 3: copy one line at a time into the shell. Notice the result as you execute each line. If error message, read carefully and correct the errors.
data = 12 data Data Data = 34 data Data 3data = "hello" data3 = "world" data3 = hello hot = 273 + 100 273 + 100 = hot hot hot - 100 hot cold = hot - 300
Your To-Do List¶
Check out the TA hours!
By the end of today
- Pre-Survey: Please submit this "quiz" if you haven't already!
- Get the required textbook and read Chapter 1: Statements
If late addig the course
- Installing Thonny, flake8
- Complete the Chapter 1 "orange" textbook activities, must do this through canvas to receive credit.
Due Wednesday at 11pm