Detailed schedule and resources
Class 36
There is no class meeting for this lecture slot. A prerecorded video lecture is available instead (links to Moodle):
Code for the video lecture is also available:
Class 35
Written exam 2.
Class 34
Exam review session.
Class 33
- Challenges and solution for objects, values, and references:
- Bring review questions for exam review next time.
Class 32
- Code for the reduce, map, and filter list processing patterns:
- Code and files for
join
andsplit
string methods:
Class 31
- Code for list basics:
Class 30
- Code for CSV files:
Class 29
- Here is a link to the crosswords file mentioned in the textbook:
- https://www.gutenberg.org/files/3201/files/CROSSWD.TXT
- We won’t use the crosswords file in class, but you can use it to understand the textbook properly and do the optional textbook exercises.
- Here is a file containing two poems that we will use in class:
- In class we will work on tasks such as:
- print the first line of the poems file
- print the first five lines of the poems file
- save every second line in a new file called
some-lines.txt
- print the two lines that tell us the authors of the poems (they begin with “BY”)
- find the empty line separating the two poems and print its line number
- save the first poem in a new file called
first-poem.txt
, and the second poem in a new file calledsecond-poem.txt
- Solutions to the first few tasks above are available:
Class 28
- More string method challenges:
Class 27
- Code for string methods:
Class 26
- Code for string indexing, slices, and iteration:
Class 25
- Code for practicing debugging:
Class 24
- We continue from Class 23, covering the
break
keyword - The rest of the class presents two examples of interesting
algorithms:
- finding square roots using Newton’s method (from textbook section 7.5);
- solving an equation using the bisection method.
- Note that detailed knowledge of these algorithms is not required for this course. These are just intended as interesting examples, to demonstrate the power of what we have already learned this semester. You are not required to memorize Newton’s method or the bisection method.
- Example code:
Class 23
- Code for demonstrating while loops:
Class 22
- Please complete the anonymous mid-semester survey.
- Code for demonstrating test functions:
Class 21
-
Please read the instructions for Lab 6 and complete the required preparation before the start of our next lab session.
-
Code for fruitful recursion examples:
Class 20
- Code for fruitful function examples:
Class 19
- Advising discussion for course selection. Please see the notes on course selection.
- Code introducing the idea of recursion: recursion_example.py
Class 18
Written exam 1
Class 17
Exam review
Class 16
Social/Ethical class III: Social good in computing. Some students were absent for legitimate reasons and requested notes on the class content, so these notes are being made available to all students out of fairness:
Class 15
Code for demonstrating guardians:
Class 14
Code for demonstrating and encapsulation and generalization:
Code for demonstrating factoring out repeated code:
Class 13
Social/Ethical discussion II. See Readings web page.
Class 12
Announcements:
- The reading for Monday is available on the Readings page.
- Updated version of HW4 is available (same questions, but with some additional hints and clarifications).
Topics for today’s class:
- Overview of how to book an appointment with a QR tutor at the QR center.
- Informal discussion of the scope of a variable: most variables and parameters are local.
- Review of call stack and debugging.
- Printing on the same line from multiple
print()
statements. - Review of void and fruitful functions.
Class 11
Demo code: debug_demo.py, callstack_demo.py
Class 10
Social/Ethical discussion I. See Readings web page.
Class 9
Mostly review of chained and nested conditional statements.
We want to write a function decide(hungry, tired)
that prints output according to
hungry | not hungry | |
---|---|---|
tired | get takeout | sleep |
not tired | cook dinner | watch Netflix |
Example code: (try to figure out for yourself?) decide.py
Also Boolean variables and parameters – see SSG11.
Class 8
We cover cascading conditional statements and nested conditional statements. Example Python code: convert_miles2.py
We will also go over sections 8 to 10 of the supplementary study guide, which are needed for lab this afternoon.
Please take a look at the extra question that is in the solutions of homework assignment 2. You need to understand how to answer this type of question (distinguishing between function calls in a module and method calls on an object).
Class 7
Today we cover topics from the assigned textbook reading, including
floor division and modulus, boolean expressions, relational operators
(==
, !=
, >
, >=
etc.), logical operators (and
, or
, not
),
conditional execution (if
, else
).
Example Python code (but try to do the warmup exercise yourself before looking at this): convert_miles.py, boolean_demos.py
Optional: A “real” example of using conditionals, using the Scratch
programming language: Potion making, by Scratch user cc196. Click on “See inside” then “Backdrops 1” to see a lot of nested if/else
s
Class 6
Today we cover Sections 4-7 of the supplementary study guide: nested
for
loops; constructors; graphics.py
; methods and dot notation.
Just for interest: if you want to find out about one of the areas of computer science that I’m interested in, check out today’s episode (September 8) of a radio show called The Academic Minute, which is broadcast on about 70 radio stations in North America. It’s also available as a podcast: The Academic Minute NPR podcast
Code from class (slightly improved version compared to what was shown in class): graphics_demo.py
Class 5
Agenda for today’s class:
- We’ll go over the supplementary study guide content about
for
loops, which explains how to use the loop variable. - We’ll begin working through the textbook exercises in section 4.3.
Useful tip: Learn how to use IDLE’s Indent Region and Dedent Region features, in the Format menu.
Class 4
Important note about the teaching style in this course: Many concepts will not be covered during our lecture session. It is essential to read the textbook carefully and ask questions on any content you don’t understand. For example, the assigned reading for Class 3 included the important concept of string concatenation, but we did not discuss that during class.
New link on main homepage: supplementary study guide.
Plan for today: We will go over some key concepts from the assigned reading, especially how to define new functions and how to generate random numbers.
Note that for section 13.2, you are not expected to understand all of this content. The only things we need from this section are:
import random
random.randint()
Hopefully you will never need this advice, but just in case…
-
At the end of class, we saw a mysterious “unexpected indent” error from IDLE. Usually, this is caused by indenting your code incorrectly. However, it can also be caused by certain invisible characters in the Python file. Different computer systems use different specialized characters for representing the end of a line, and it is possible for IDLE to report these characters as causing an indentation error. One easy way to remove all unwanted end-of-line characters is to copy and paste your code into this end-of-line fixer website. Click “Convert line endings to LF”, copy the output into a new file, and now the weird characters have been removed from your Python script.
-
I have also occasionally seen the presence of certain invisible characters prevent IDLE from saving a file. If IDLE refuses to save, you should create a new file and paste your code into it after following step 1 above to ensure that any weird invisible characters have been removed.
Class 3
- Make sure that you have Show File Extensions turned on in your
operating system. For example, you must be able to see the
.py
at the end of your Python files, when browsing folders. - When opening a Python file, do not just double-click on it in the folder view. First open the IDLE application, then use the Open command in the File menu.
Today we review the concepts in the assigned reading, including script mode, order of operations, string operations, comments, function calls, and math functions.
Example programs: area.py, ask_question.py
Class 2
We will review the concepts in the assigned reading, then look ahead to some things needed in the afternoon lab: commenting out code; the distinction between executing code via the console and running Python scripts.
Here are a couple of clarifications of the assigned reading material:
- In this course, we use Python 3 (not Python 2), the same as recommended by the textbook.
- For running Python in a web browser, the textbook author recommends pythonanywhere.com. Another good option is replit.com, which we played around with in the last class meeting.
- However, in this course we will mostly be learning to write programs using files on our own computer and running Python on our own computer (not in the cloud inside a web browser). For this, you should use the IDLE editor. This comes bundled with a standard Python download, which is available at python.org
Pair programming will be discussed if we have time, otherwise we can talk about it in lab. Key ideas:
- There are two roles, driver and navigator. The driver uses the keyboard and mouse to write and run code, whereas the navigator assists by making suggestions.
- You must switch roles at least every 30 minutes.
Class 1
- We will play around a little on replit.com, but this will mostly be an informal introduction to the course.
- Please read the syllabus carefully and bring any questions to the next class.
- Note the required reading: complete this before the next class.
- Note when the first homework assignment is due.
- Finally, don’t forget we have a lab on Wednesday at 3 PM.
—- Last modified: Thu Nov 16 22:11:30 UTC 2023 by jmac.