Aug 26: Style Guide; Python Statements; Types
Learning Objectives
After today's class, you should be able to:
- Explain what a PEP is and why PEPs are important.
- Run ruff to check your code before submitting.
- Explain differences between a program's code and output
- Identify and execute Python functions for input and output
- Write assignment statements and use variables
Lesson Outline¶
Announcements
-
See the Help page:
- TA Hours (Sun–Thu) and Office Hours (Tuesday, Wednesday, Thursday and by appointment)
- Ask and answer questions on Piazza (anytime)
-
Textbook readings and exercises are due every Tuesday at 3pm
- Homeworks (programming assignments) are due every Wednesday by 11:59pm
Python Style Guide: Required for all python submissions
- PEP = Python Enhancement Proposal
- PEP 8 – Style Guide for Python Code
- Prettier version: https://pep8.org/
- PEP 257 – Docstring Conventions
- Real-world example: Google's style guide
- PEP 8 – Style Guide for Python Code
- Check your code before submitting on Canvas!
Mini Exercise I
Lecture
Fixing Style
- Download payroll.py
- Use Thonny, run payroll.py first to see how it works
- Run
!ruff check 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 ruff by pressing Up+Enter in the shell
- If you finish early, try making other style defects
- See Rules | Ruff for examples
Mini Exercise II
Thonny Tips¶
Quick Demo
- Have you discovered the View menu in Thonny?
- Consider showing "Files" and "Variables"
- Other windows might be useful to you
- Tools > Options… Theme & Font
- UI theme: Clean Dark
- Syntax theme: Tomorrow Night Eighties
- Feel free to choose the ones you want!
Your To-Do List¶
- Due tomorrow (Wednesday by 11:59pm)
- HW 1 on Canvas
- HW1 Reflection on Canvas
- Due September 2nd (Tuesday 3pm)
- Textbook readings
Code for Activity¶
Model 1 – copy code 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