Skip to content

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

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

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 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