Introduction to Computer Programming I

CSI31

Professor Luis Fernandez

Tuesday, Thursday, 10:00am-11:50am, room CP 320

 
0
Date Details and class materials HW assignment
Week 1
02/01 Topics to be covered:

1.1 The Universal Machine
1.2 Program Power
1.3 What is Computer Science?
1.4 Hardware Basics

Lecture slides: lecture1.pdf

Lecture video about Hardware (from YouTube): https://youtu.be/ctAVC2JwEwI

First program: myFirstProgram.py
HW 1

Install Python 3.6.2 in your computer

Register in codelab. Create a username and enter

Do from textbook (not graded):
  • p. 21 True/False (1,2,3,4) -
  • p. 22 Multiple Choice (1,2,3,4) -
  • p.23 Discussion (1 (a), 2) -
Submit (GRADED):
  • Nothing this time.
Do in codelab:
  • Assignment of variables (all) (Due 02/03)
02/03 Topics to be covered:
1.5 Programming Languages
1.6 The Magic of Python
1.7 Inside a Python Program
1.8 Chaos and Computers

Lecture slides: CSI31-lecture02.pdf

Programs: chaos.py , chaos_comments.py

Other files: In-class assignment :
CSI31-lecture02InClassAssignment.pdf
HW 2

Do from textbook (not graded):
  • pp. 24-25 (Programming exercises): 1, 4, 5
  • pp. 20-21, read section 1.9 Summary.
    Summary for those who don't have a book yet: page 1 , page2 .
  • pp. 21-22 True/False (5-10)
  • pp. 22-23 Multiple Choice (1, 2, 5-10)
  • p. 23 Discussion (1 (b-f), 5) -
Submit (GRADED) Due Thursday 02/10:
  • p. 25: Exercises 4,5.
  • Write a program that asks the user for 3 numbers and then prints out the product, the sum, and the average of the three numbers.
Do in codelab:
  • Arithmetic expressions (all) (Due 02/10)
Pictures of Chapter 1 Exercises for those who don't have a book yet: page 21 , page 22 , page 23 , page 24 , page 25

Answers to T/F, Multiple Choice and Discussion questions from Chapter 1: CSI31Chapter1answers.pdf


Week
02/08 NO CLASS. CUNY follows a Friday schedule
02/10 Topics to be covered:
2.1 Software Development Process
2.3 Elements of Program
2.4 Output Statements
2.5 Asssignment Statements

Lecture slides: CSI31-lecture03.pdf

Programs: area.py , area_2.py

In-class assignment : CSI31-lecture03InClassAssignment.pdf
HW 3

Do from textbook (not graded):
  • Read Sections 2.1-2.5
  • p. 51 True/False (1-8)
  • p. 52 Multiple Choice (4-6)
  • Programming exercises. Page 55: 3, 9, 10
Submit (GRADED):
  • p. 55: 9,10. Due Tuesday 02/15
  • Exercise 3 from in-class assignment. Due Tuesday 02/15
Do in codelab:
  • Assignment - Exchanges (Due 02/15)
Chapter 2 answers to True/False and Multiple Choice questions: CSI31Chapter2answers.pdf

Week 3
02/15 Topics to be covered:
2.6 Definite Loops
2.7 Example Program: Future Value

Lecture slides: CSI31-lecture04.pdf
programs: for_loop_list.py , futureValue.py

In-class assignment : CSI31-Lecture04_In-ClassAssignment.pdf
HW 4

Do from textbook (not graded):
  • Read Sections 2.6-2.8
  • p. 51 True/False: 9, 10
  • p. 52 Multiple Choice: 8, 10
Submit (GRADED) - Due Tuesday 02/22 :
  • Write a program that reads in twelve numbers using a for loop (from the user, from the keyboard) and then outputs:
        - The sum of all the numbers,
        - The sum of squares of all the numbers, and
        - The average of all the numbers
Do in codelab:
  • Assignment - For and ranges, part 1 (Due 02/22)
02/17 Topics to be covered:
3.1 Numeric Data Types
3.2 Type Conversions and Rounding
3.3 Using Math Library
3.4 Accumulating Results: Factorials

Lecture slides: CSI31-lecture05.pdf
programs: example.py , factorial.py

In-class assignment : CSI31-lecture5InClassAssignment.pdf ,
InClassAssignment1_sketch.py ,
HW 5

Do from textbook (not graded):
  • Read Sections 3.1 - 3.4
  • Page 76, True/False: 1, 3, 5.
  • Page 77, Multiple Choice: 1-3.
  • Pages 79-82, Programming exercises: 2, 15, 16.
Submit (GRADED)
  • Page 82: 15,16. Due Tuesday 02/22
Do in codelab:
  • Assignment - For and ranges, part 2 (Due 02/22)
Chapter 3 answers to True/False and Multiple Choice questions: CSI31Chapter3answers.pdf

Week 4
02/22 Topics to be covered:
3.4 Limitations of Computer Arithmetic
7.1 Simple Decisions
7.2 Two-Way Decisions

Lecture slides: CSI31-lecture06.pdf
programs: wage.py , wage_mod.py , simpleDecision.py

In-class assignment : CSI31-lecture06InClassWork.pdf
HW 6

Do from textbook (not graded):
  • Read Sections 3.4, 7.1, 7.2
  • Page 236, True/False: 1, 4, 6.
  • Page 236, Multiple Choice: 1-5.
  • Pages 238-240, Programming exercises: 1, 2, 3, 7.
Submit (GRADED)
  • Page 239: 3, 7. Due Tuesday 03/01
Do in codelab:
  • Assignment - if-else (Due 02/24)
02/24 Topics to be covered:
7.3 Multi-way Decisions
7.4 Exception Handling
7.5 Study in Design

Lecture slides: CSI31-lecture07.pdf
programs: quadratic-equation.py , quadratic-equation_mod.py , quadratic-another.py , quadratic-another2.py

In-class assignment : CSI31_lecture07InClassWork.pdf
answers/solutions : CSI31_lecture07InClassWorkAnswers.pdf
HW 7
Due 03/01:

  • Write a program that reads in 14 numbers from the user (from keyboard), and outputs:
    - the sum of all negative numbers,
    - the sum of all positive numbers,
    - the number of zeros,
    - the average of positive numbers,
    - the average of negative numbers,
    - the average of all numbers.
    Use exception handling for the cases when an letter of a string is provided instead of a number. In such a case just terminate the program.
    Don't forget to comment your program!

    Hints : (use for loop; count negative numbers and positive numbers),
    at each iteration take the next inputted number
    if it is negative - add it to the sum of all negative numbers, increment the counter of negative numbers
    if it is positive - add it to the sum of all positive numbers, increment the counter of positive numbers
    if it is zero, increment the counter for the zeros,
    When the loop is over, you'll have a sum of all negative numbers, and the sum of all positive numbers, along with the numbers of negative and positive numbers, and the number of zeros. So you'll know how to find the averages.

    Here is a grading rubric for this exercise:
    - the sum of all negative numbers is found correctly ( 1 point ),
    - the sum of all positive numbers is found correctly ( 1 point ),
    - the number of zeros is found correctly ( 1 point ),
    - the average of positive numbers is found correctly ( 1 point ),
    - the average of negative numbers is found correctly ( 1 point ),
    - the average of all numbers is found correctly ( 1 point ),
    - exception handling is used and is used properly ( 2 points ),
    - comments are present and they are meaningful( 1 point ),
    - clear input/output messages ( 1 point )

  • Write three different programs that find the maximum of three numbers. The user will input the numbers from the keyboard. You can choose three from four: each to all , decision tree method , sequential processing and Pythons built-in function max .

Chapter 7 answers to True/False and Multiple Choice questions: CSI31Chapter7answers.pdf

Week 5
03/01 topics:
4.1 Overview
4.2 The object of objects
4.3 Simple graphical programming
4.4 Using Graphical Objects

Lecture slides: CSI31-lecture08.pdf

Programs: example1.py , anySizeWindow.py , points.py

Graphics library: graphics.py

Reference Manual for graphics library: graphics.pdf

Web-page for graphics library: http://mcsp.wartburg.edu/zelle/python/

In-class assignment : CSI31-lecture08InClassAssignment.pdf
inClassAssignment1_sketch.py
HW 8

Do from textbook (not graded):
  • Read Sections 4.1 - 4.4
  • Page 123, True/False: 1-4.
  • Page 123, Multiple Choice: 1-3.
  • Look through the graphics library reference manual (graphics.pdf on the left).
  • Pages 126-128, Programming exercises: 3, 8.
Submit (GRADED) Due Tuesday 03/08
  • Write a program that draws a house (no colors, just outlines), then by a click of a mouse in the graphics window colors the house, and finally by another click of the mouse closes the graphics window. Don't forget to comment your program!
Do in codelab:
  • Nothing today
Topics:
We spent most of the class working in one of the homework exercises, namely exercise 7 from page 239. We did not cover any new material.
HW 8

Submit (GRADED) Due Thursday 03/10
  • Page 239-240, exercises 4 and 11.
Do in codelab:
  • Nothing today
Chapter 4 answers to True/False and Multiple Choice questions: CSI31Chapter4answers.pdf

Midterm exam will take place on Tuesday, March 22 nd
Week 6
Topics:
4.4 Using Graphical Objects (continues)
4.5 Graphing Future Value
4.7.1 Mouse Clicks

Lecture slides: CSI31-lecture09.pdf
programs: ovals.py , ovals-corrected.py , future-price-text.py , future-price-graphics.py , mouseClicks.py , future-price-graphics_mod.py

In-class assignment : CSI31-lecture09InClassAssignment.pdf
answers/solutions : inClassAssignment.py
HW 9

Do from textbook (not graded):
  • Read Sections 4.5-4.7
  • Pages 126-128, Programming exercises: 7, 8, 9.
Submit (GRADED) Due Thursday 03/10
  • Page 127: 8, 9.
Do in codelab:
  • Nothing today
03/08 Topics:
4.6 Choosing coordinates
4.7 Interactive Graphics

Lecture slides: CSI31-lecture10.pdf

Programs: quadrilateral.py , tic-tac-toe_begin.py, conversion.py , slideshow.py

Pictures for slideshow: Celtic-tree-of-life.gif , tree-of-life.gif , TreeOfLife.gif

In-class assignment : CSI31-lecture10InClassAssignment.pdf
HW 10

Do from textbook (not graded):
  • Read Sections 4.5-4.7
Submit (GRADED) Due Thursday 03/17
  • Write a program that upon user's choice of the speed (LOW, MEDIUM, HIGH - should be done as buttons in the graphics window) shows how a ball is falling from the top part of the graphics window, down to the bottom part of the window. The falling should be smooth. Use buttons for the speed selection. You can use these pictures of the balls or find any other online.
                   
Do in codelab:
  • Nothing today


Week 7
03/10 topics:
5.1 The String Data Type
5.2 Simple String Processing
5.3 Lists as Sequences

Lecture slides: CSI31-lecture11.pdf
programs: string_operations.py , months_lists.py

In-class assignment : CSI31-lecture11InClassAssignment.pdf
HW 11

Do from textbook (not graded):
  • Read Sections 5.1-5.3
  • Multiple choice: p. 169: 1, 2.
  • Page 171, Programming exercises: 4, 5.
Submit (GRADED) Due Thursday 03/24
  • Page 171: 4, 5.
Do in codelab:
  • Strings (I)
03/15 topics:
5.4 String representation and message encoding
5.5 String methods
5.6 Lists have methods, too
5.7 From encoding to encryption

Lecture slides: CSI31-lecture12.pdf

Programs: encoding.py , decoder.py , date.py , CaesarCipher-encoding.py

In-class assignment : CSI31-Lecture12_inClassAssignment.pdf ,
HW 12

Do from textbook (not graded):
  • Read Sections 5.4-5.7
  • Page 172, Programming exercises: 6, 9, 10.
Submit (GRADED) Due Thursday 03/24
  • Page 172: 9, 10.
Do in codelab:
  • Strings (II)

Week 8
03/17 topics:
5.8 Input/Output as String Manipulation
5.9 File processing

Lecture slides: CSI31-lecture13.pdf

Programs: readAllfromFile.py , readAllfromFile_mod.py .
createDataFile.py , processDataFile.py

Files: data.txt , numbers.txt , names.txt donquijote.txt

In-class assignment : CSI31-lecture13InClassAssignment.pdf .
HW 12

Do from textbook (not graded):
  • Read Sections 5.8-5.9
  • True/False: page 168, 6-10
  • Multiple choice: page 169, 3-10
  • Page 172, Programming exercises: 14.
Submit (GRADED) Due Thursday 03/31
  • Page 172: 14.
Do in codelab:
  • Files
03/22 Midterm exam
Study guide: CSI31_midterm_exam_studyGuide.pdf

Part 1 : you can use textbook, your notes, pdf of the book, but no Python Interpreters nor search engines (1 hour long).

Part 2 : you can use textbook, your notes, and computers (50 minutes long).
 

Week 9
03/24 Topics: Chapter 6. Defining Functions
6.1 The Function of Functions
6.2 Functions, Informally
6.3 Future Value with a Function
6.4 Functions and Parameters: The Details
6.5 Functions That Return Values

Lecture slides: CSI31-lecture14.pdf

Programs/input files: four_numbers.py , square.py , removeSpaces.py

In-class assignment : CSI31_lecture14InClassAssignment.pdf , InClassAssignment2_draft.py , InClassAssignment3_draft.py
HW 14

Do from textbook (not graded):
  • True/False questions: page 203, 1-7.
  • Read Sections 6.1-6.5
  • Multiple choice questions: page 204, 1-5.
  • Programming exercises: page 206-208: 3, 4, 9, 10, 12.
Submit (GRADED) Due Thursday 04/07
  • Page 207: 4, 12.
Do in codelab:
  • Functions - defining
03/29 Topics: Chapter 6. Defining Functions
6.5 Functions That Return Values (continued)
6.6 Functions that Modify Parameters
6.7 Functions and program structure

Lecture slides: CSI31-lecture15.pdf

Programs: prog1.py , prog2.py , prog3.py , tests.py

In-class assignment : CSI31_lecture15inClassAssignment.pdf , InClassAssignment2.py , InClassAssignment3.py

Link for in class assignment.
HW 15

Do from textbook (not graded):
  • True/False questions: page 203, 8-10.
  • Read Sections 6.6-6.9
  • Multiple choice questions: page 204, 6-10.
  • Programming exercises: page 206-208: 7, 11, 13.
Submit (GRADED) Due Thursday 04/07
  • Page 207: 11, 13.
Do in codelab:
  • Functions - invoking
Chapter 6 answers to True/False, Multiple Choice and Discussion questions: CSI31Chapter6answers.pdf

Week 10
03/31 Topics: Chapter 8. Loop structures and booleans
8.1 For loops: a quick review
8.2 Indefinite loops
8.3 Common loop patterns: interactive, sentinel

Lecture slides: CSI31_lecture16.pdf

Programs/input files: example1.py , average_i.py , average_s.py , average_s_mod.py , average_i_exceptions.py , average_s_mod_exceptions.py , average_file.py , average_file_mod.py , input.txt , input2.dat , input3.dat

In-class assignment : CSI31_lecture16InClassAssignment.pdf

Answers/solutions : CSI31_lecture16InClassAssignmentAnswers.pdf , InClassAssignment3.py
HW 16

Do from textbook (not graded):
  • Read Sections 8.1-8.3
  • True/False questions: page 277, 1-6.
  • Multiple choice questions: pages 277-278, 1-3.
  • Programming exercises: pages 279-282: 2, 3, 4, 5.
Submit (GRADED) Due Thursday 04/14
  • Page 280: 4, 5.
Do in codelab:
  • While loops. Input testing loops.
04/05 Topics: Chapter 8. Loop structures and booleans
8.3 (Continues) Common loop patterns: nested loops
8.4 Computing with booleans
8.5 Other common structures: post-test, loop and half

Lecture slides: CSI31_lecture17.pdf

Programs/input files: read_all_numbers.py , temperature.py , temperature_infiniteLoop.py

In-class assignment : CSI31_lecture17InClassAssignment.pdf

Answers/solutions : CSI31_lecture17InClassAssignmentAnswers.pdf
HW 17

Do from textbook (not graded):
  • Read Sections 8.4-8.6
  • True/False questions: page 277, 7-10.
  • Multiple choice questions: pages 277-278, 4-10.
  • Programming exercises: pages 279-282: 8, 14, 15.
Submit (GRADED) Due Thursday 04/14
  • Pages 280-282: 14, 15.
Do in codelab:
  • While loops. Input testing loops.
LIST OF FINAL EXAM PROJECTS AND INSTRUCTIONS

Chapter 8 answers to True/False, Multiple Choice and Discussion questions: CSI31Chapter8answers.pdf

Week 11
04/12 Topics: Chapter 9. Simulation and Design
9.1 Simulating racquetball
9.2 Pseudo-random numbers
9.3 Top-down design
9.4 Bottom-up implementation

Lecture slides: CSI31_lecture18.pdf

Programs/input files: racquetball.py

In-class assignment : CSI31_lecture18InClassAssignment.pdf
HW 18

Do from textbook (not graded):
  • Read Sections 9.1-9.5
  • True/False questions: page 307, 1, 2, 4--7.
  • Multiple choice questions: pages 307--308, 1-5.
  • Programming exercises: pages 309--312: 11, 12.
Submit (GRADED) Due Thursday 04/28
  • Page 311: 11, 12.
Do in codelab:
  • Nothing this week.
04/14 Topics: Chapters 9 and 10
9.5 Other design techniques

Lecture slides: CSI31_lecture19.pdf

In-class assignment.
It will count as extra credit.

Read the lecture slides and implement a simulation of the craps game (you will find the description and help in the slides).

NOTE: The deadline to submit it is today Thursday April 14th at 2pm.

Drop your file (with your name) in this folder:
Link to submit in class assignment
HW 18

Do from textbook (not graded):
  • Read Sections 9.1-9.5
  • True/False questions: page 307, 3, 8, 9.
  • Programming exercises: work on your final project.
Submit (GRADED) Due Thursday 04/28
  • Nothing new. Work on your final project.
Do in codelab:
  • Nothing this week.
Chapter 9 answers to True/False, Multiple Choice and Discussion questions: CSI31Chapter9answers.pdf
04/19
and
04/21
NO CLASS: Spring break


Week 12
04/26 Topics: Chapter 10. Defining Classes
10.1 Quick review of objects
10.2 Example program: target
10.3 Defining new classes

Lecture slides: CSl31_Lecture20.pdf
Programs/input files: target.py , target_mod.py , dice.py , dice_graphics.py , die1.gif , die2.gif , die3.gif , die4.gif , die5.gif , die6.gif , two-red-dice.gif

In-class assignment : CSl31_Lecture20InClassAssignment.pdf , inClassWork2.py
HW 19

Finish in-class assignment

Do from textbook (not graded):
  • Read Sections 10.1-10.3
  • True/False questions: page 356, 1, 6, 10.
  • Programming exercises: page 360: 9, 10, 11.
Submit (GRADED) Due Thursday 05/05
  • page 360: 10, 11.
Do in codelab:
  • class definition.
04/28 topics: Chapter 10. Defining Classes
10.4 Data processing with class
10.5 Objects and encapsulation
10.6 Widgets

Lecture slides: CSl31_Lecture21.pdf
programs/input files: studentsGPA.py , students.txt , program.py , button.py , die.py , dieView.py , die1.gif , die2.gif , die3.gif , die4.gif , die5.gif , die6.gif , two-red-dice.gif

In-class assignment : CSl31_Lecture21InClassAssignment.pdf , carddeck.zip cardTesting.py
answers/solutions : will not be posted
HW 20

Finish in-class assignment

Do from textbook (not graded):
  • Read Sections 10.4-10.6
  • Programming exercises: page 360: 13.
Submit (GRADED) Due Thursday 05/05
  • page 360: 13.
Do in codelab:
  • class definition.
Chapter 10 answers to True/False, Multiple Choice and Discussion questions: CSI31Chapter9answers.pdf

Week 13
05/03 Topics: Chapter 11. Data Collections
More about classes
11.1 Example problem: simple statistics
11.2 Applying lists
11.3 Lists of records

Lecture slides: CSl31_Lecture22.pdf
programs/input files: conventionsExample.py , targetClass.py , usingTarget.py , simpleStats.py , input1.txt , input2.txt , student.py , studentOrderingByGPA.py , students.txt

In-class assignment : CSl31_Lecture22InClassAssignment.pdf
HW 21
Do from textbook (not graded):
  • Read Sections 11.1-11.3
  • Programming exercises: page 413: 7.
Submit (GRADED) Due Thursday 05/12
  • page 413: 7.
Do in codelab:
  • Nothing this week
05/05 topics: Chapter 11. Data Collections
11.4 Designing with lists and classes
11.7 Non-sequential collections


Lecture slides: CSl31_Lecture23.pdf
programs/input files: othello.py , students.txt , studentsRecordsAsDictionary.py

In-class assignment : CSl31_Lecture23-inClassAssignment.pdf
answers/solutions : to be posted
HW 22
Do from textbook (not graded):
  • Read Sections 11.4-11.7
  • True/False questions: Page 410: all
  • Multiple choice questions: Page 411: all
  • Discussion: Pages 411-412: all
Submit (GRADED) Due Thursday 05/12
  • Page 414: 16.
Do in codelab:
  • Nothing this week
Week 14
05/10 Review

Slides: lecture24noAnswers.pdf
Answers: CSI31_Lecture24withAnswers.pdf
05/12 Review

Slides: CSI31_Lecture25noAnswers.pdf
testing set: testingSet.py

Answers: CSI31_Lecture25withAnswers.pdf
set (solution): CSI31_Lecture25_set.py



Week 15
05/17 Last day of class. Review.
05/24 Final Exam

  The Final Grade is composed of:
  HWs (30%)
  Midterm Exam (20%)
  Final Project (20%)
  Final Exam (30%)