NPRG030 Programming 1 (winter 2023-4)

Instructors:

This course is a fast-paced introduction to programming and basic data structures, with a strong emphasis on learning to write working code. It assumes no previous programming experience. The course uses the Python programming language.

Throughout the course students will complete many programming exercises in Python, solving a wide variety of programming problems.

Lectures and other meetings

Requirements

This is a pass/fail course: you will not receive a numeric grade.

To pass this class, you must fulfill the following requirements by Friday, February 16, 2024 at the end of the exam period:

  1. Complete a number of programming exercises through the semester. The tutorial teachers will assign these exercises weekly, and you can submit your solutions to the ReCodEx automated grading system. To pass, you will need to earn at least 70% of the total possible points. Any points that you earn over 90% (up to a maximum of 10%) will be applied as bonus points to your test score when you take the test.

  2. Pass a written test at the end of the semester.

  1. Write a program in Python as a semester project. Your program should accomplish something that is interesting, cool, or fun and can be 100-300 lines long, or longer if you like. Here are some project ideas. Please send your tutorial teacher a 1-2 paragraph project proposal by Sunday, December 3. A first working version of your project is due by Sunday, January 21 and a final version by Sunday, January 28.

  2. Regularly attend the lectures and tutorials and participate in class.

You may not use ChatGPT, Copilot or other AI tools to generate code that you submit in any homework assignment or semester project in this course. Any use of such tools is considered cheating and may disqualify you from passing the class.

Textbooks

Resources

Syllabus

This is a rough map of the ground we plan to cover in this class. (It will probably evolve as the semester goes on.)

October 2 (notes) (exercises)
Introduction. Operating systems. The command line. Built-in types: integers, booleans, floats, strings. Numeric operators. Comparison operators. Type conversions. Using an IDE. Variables. The input() and print() functions. Conditional statements: if and else. Elif. Comments. While loops. For loops. Ranges.
October 9 (notes) (exercises)
Boolean operators. More assignment operators. More about ranges. Break and continue. Nested loops. Math functions. Random numbers. Reading lines of standard input. Redirecting input and output. String indexing.
October 16 (notes) (exercises)
ASCII and Unicode. chr() and ord(). String slicing. Functions vs. methods. String methods. Lists. List indexing and slicing. Mutating lists. More list operations. Structural and reference equality.
October 23 (notes) (exercises)
Splitting and joining strings. String formatting. Running time of list operations. Nested lists. Tuples. Multiple assignment. Lists of tuples. Function definitions. Local and global variables. Plotting with matplotlib.
October 30 (notes) (exercises)
Conditional expressions. None. Locals and globals, continued. Passing by value and reference. Variable numbers of arguments. Recursion. File input/output. The 'with' statement.
November 6 (notes) (exercises)
Default parameter values. Keyword arguments. Assertions. Objects and classes. Writing initializers with __init__. Writing methods. __repr__. More on 'import'. Installing packages.
November 13 (notes) (exercises)
'else' clauses with 'while' and 'for'. Command-line arguments. Magic methods for operator overloading. Sets. Dictionaries.
November 20 (notes) (exercises)
Iterables and sequences. List comprehensions. Set and dictionary comprehensions. Iterating with enumerate() and zip().
November 27 (notes) (exercises)
Functions as values. map and filter. Lambda expressions. Nested functions. The 'nonlocal' keyword. Dictionaries with defaults.
December 4 (notes) (exercises)
Raising and catching exceptions. Class objects. Class attributes, class methods. Inheritance.
December 11 (notes) (exercises)
Inheritance versus composition. Testing an object's type. The 'match' statement. Magic methods for equality.
December 18 (notes) (exercises)
User interfaces with Tkinter. The Canvas widget. Event handling. Model-view architecture.
December 25
No lecture (winter vacation)
January 1
No lecture (winter vacation)
January 8 (notes) (exercises)
Type checking. Type hints. Dataclasses. Comma-separated values. Writing good code. Software testing. Unit, regression and integration tests.