Lecture calendar

Notes will sometimes be posted in advance, but all notes are subject to change. Old notes from 2022 are available for reference, and will be refreshed throughout the semester

                  LecturesReading and Materials
Week 1

Lecture 1: Welcome to ESC180. Expressions and variables. A very simple program. YouTube livestream

Suggested readings for the next couple of lectures: Downey chapters 1-2 and/or Gries chapters 1-2. Note: you're only responsible for the material in lecture. However, some people learn best by reading, which is why I'm listing readings.

Learning outcomes: be able to run a very simple Python program in Pyzo. Undrestand that a program is a series of instructions. Understand what syntax is, both in natural (human) languages and in programming langueges

Week 2

Lecture 1: Welcome to ESC180, part 2. Conditionals, cont'd. Conditionals. . YouTube Livestream

Youtube videos on tracing: Part 1, Part 2, Part 3.

Lecture 2: A little bit on errors and how Python runs. The quadratic equation, string literals, 2022 Zoom recording. YouTube livestream

Lecture 3: numerical literals. More on finite precision. Functions; global and local variables. 2022 Zoom recording ver. 1, 2022 Zoom recording from ver. 2. YouTube livestream



Suggested readings continue reading Downey Ch. 1-2 and/or Gries Ch. 1-2.

Suggested readings: Downey Ch. 3, Gries Ch. 3

Optional aside for people who like irrational numbers: you cannot store most irrational numbers in computers: there is just not enough space to store an infinite number of digits. So what can you do? You can store a string like "pi", and hope that's interpreted in a sensible way. Of course, most irrational numbers aren't named! You can also store Python code that generates the irrational number in question to arbitrary precision (coming up in a few weeks: code to compute numbers like sqrt(2) and π). But note that there are uncountably many irrational numbers, but only countably many Python programs. That means that you still can't hope to represent almost any irrational numbers.

Learning outcomes: Be able to trace Python programs in Pyzo. Understand the distinction between syntax errors and "name not found" errors in Python. Be able to identify some syntax errors and some name not found errors in simple examples. Understand that Python executes code line-by-line and understand why Python cannot find "name not found" errors ahead of time. Understand that string, float, and int types are different. Understand the difference between int and floats types. Understand the limitations of the float types. Understand why comparisons between floats and ints can be problematic. Understand why physical measurements can usually be stored in a float. Understand conversion between different types, and understand why e.g. "42" + 42 will produce an error but "42" + str(42) won't. Be able to write very simply functions that perform mathematical operations.

Week 3

Lecture 1: Multiple assignment and swapping variables. Functions; global and local variables, cont'd. Passing data to and from functions. 2022 Zoom recording from 10am, 2022 Zoom recording from 3pm. YouTube live stream 2m, YouTube livestream 3pm.

Lecture 2 Functions; global and local variables, cont'd. Types (notes to be posted). . Zoom recording. YouTube livestream

Lecture 3 Passing data to and from functions, cont'd. Integer division and modulo operators. For loops. While loops. Zoom recording. YouTube livestream Control flow using return

Reading: Downey Ch 1.5, Downey 7.1-7.4 or Gries 9.1-9.3. (Note: the lecture content this week is a bit different from the way things are covered in either textbook).

For completeness: PEP 8, the official Python style guide, Python operator precedence.

Happy early Talk Like a Pirate Day! Also: The distinction between "parameters" and "arguments" is not always paid attention to, but here's an explanation. A lot of the time, the terms are used interchangeably.

Challenge/job interview question: How to swap two variables without using multiple assignments and without defining an additional temporary variable? Hint: start with a = a + b. (Follow-up, requires advanced material: what if the variables are not integers?)

Learning outcomes: Be able to write simple functions. Understand the different ways information is communicated to functions: passing an argument, modifying a a global variable to be read by the function. Understand the different ways information is communicated from functions: via return, and by modifying a global variable. Understand how for and while loops work. Be able to write for and while loops, particularly in the context of computing quantities such as x^n and properties of numbers such as primality.

Week 4

Lecture 1: Primality testing, cont'd.Implementing range using while. Intro to Project 1. Systematically testing code: the calculator example. import and initializing global variables outside the main block. YouTube livestream (2pm), YouTube livestream (3pm)

Lecture 2: While loops, More on range, Implementing range using while, YouTube livestream,

Lecture 3: Debugging with Pyzo. Systematically testing code: the calculator example. . YouTube livestream, backup Zoom room

2022 stuff below:

Lecture 1: More on range. Implementing range using while. . Zoom recording

Lecture 2: Systematically testing code: the calculator example. import and initializing global variables outside the main block. Booleans and Boolean Algebra. Converting Booleans. Zoom recording I, Zoom recording II

Lecture 3: Postmortem debugging with Pyzo (see video). Lists and looping over lists. break and continue. Zoom recording. import and initializing global variables outside the main block. Booleans and Boolean Algebra. Converting Booleans

Videos: Computing log10 using while-loops, primality testing, tracing is_prime, Converting for-loops into while-loops

For completeness: Python operator precedence.

CodingBat exercises: Logic-1, Logic-2

Reading: Downey Ch. 7, Gries Ch. 9

Week 5

Lecture 1: Interview puzzle solution: swapping variables without temporary storage. Lists and looping over lists. . Factorials and trailing zeros. Computing Pi using a Monte Carlo method. YouTube livestream, backup Zoom room

Old stuff below

Lecture 1: input, and a bit on style and design. Computing Pi using a Monte Carlo method. Heterogenous lists. List methods and functions Zoom recording

Lecture 2: List methods and functions, cont'd. Pseudorandom numbers. login example: keeping track of state. Facotorials and trailing zeros: interview puazzle solution. Zoom recording

Lecture 3: login example, continued. Solution: trailing zeros of n!, the missing K problem, Interview puzzle solution: fast trailing zeros. Nested loops intro, , avoiding nested loops using functions Zoom recording.

Reading: Downey Ch. 7, Gries Ch. 9

CodingBat exercises: List-1, List-2

Just for fun: Unix Epoch Time

Interview question: compute the number of trailing zeros in n! efficiently for large n.

Just for fun, about computing exponents: how to compute b^x when x is not an integer? This is generally done by computing power series rather than repeatdly multiplying b by itself. See Lab#3 for an example of a computation of a sum of a power series.

Just for fun, about computing exponents: how to compute b^x when x is not an integer? This is generally done by computing power series rather than repeatdly multiplying b by itself. See Lab#3 for an example of a computation of a sum of a power series.

Week 6

Lecture 1: Nested loops intro, cont;d. Strings and string methods. ReversingStrings. Anagrams. intro to exec (to be continued). Zoom recording

Lecture 2: Zoom recording

Lecture 3: start reading the memory model notes. Zoom recording

Reading: Gries Ch. 4, 7.3. Downey Ch. 8

Extra practice problems: all of CodingBat Python. String-3 and Array-3 on CodingBat Java (N.B., you'd have to test the outputs yourself).

Python 3 string methods

Week 7

Lecture 1: Zoom recording. Continue reading the memory model notes. Memory model worksheet.

Lecture 2: Zoom recording. Continue reading the memory model notes. Memory model worksheet, solutions, Exercise C video solutions

Lecture 3: Zoom recording

Week 8

Lecture 1: Zoom recording

Lecture 2: Zoom recording

Lecture 3: Zoom recording

Week 9

Lecture 1: Complexity analysis lecture. Computational complexity notes. Zoom recording

Lecture 2: Pre-lecture longest_run.py. Zoom recording (Noon), Zoom recording (3pm)

Lecture 3: Zoom recording (N.B.: watch the Noon recording for Lecture 2 for an introduction to timeit.timeit(), globals(), and locals()).

Week 10

Review session: 3pm, 6:20pm

Lecture 1: Zoom recording

Lecture 2: Zoom recording (morning), Zoom recording (aftenroon)

Week 11

Lecture 1: Zoom recording

Lecture 2: Zoom recording

Lecture 3: Zoom recording

Week 12

Lecture 1: Recorded lecture I, 0:38min-end, Recorded lecture 2, 0:0min-0:25min (passcode a99887766!)

Lecture 2 Recorded lecture (passcode: a99887766!)

Lecture 3: Recorded lecture 1, 0:25min-end, Recorded lecture 2. 0:0min-0:30min, everything else optional. (passcode a99887766!)

Week 13

Lecture 1: Zoom recording MergeSort, MergeSort analysis, MergeSort analysis II (optional, not covered in lecture)

Lecture 2: Turing and Goedel, call tree review, recursive deep copy (optional, not covered), Monte Carlo Integration (only need to know the concept of computing integrals by throwing random points on the plane, and the issues around computing f_max). Zoom recording AM, Zoom recording PM (incomplete).