Homework 2-3

Adapted from Brown University CSCI0931. Used with Permission.


For the following problems you may discuss the concepts that will help solve these problems with classmates and course staff. You may not simply copy down the answers of your classmates as that is a violation of the collaboration policy. The one exception to this rule are those problems marked as “(Independent)”. You may discuss independent problems with course staff only.

This is a short homework. Therefore, it's due in one week.

Task 1

This homework is designed to give you some practice in learning by observing. The topic that is covered is functions, which we haven't covered in class yet, so this homework is more like a preparation for next week.

Copy HW2-3a.py onto your computer. Rename it as Name_StudentID_HW2-3a.py. (This it a new version that is better formatted. If you already completed your homework with the original version HW2-3.py, that's also fine.)_

Throughout the code, there are twelve commented questions (#Q1, #Q2, etc) scattered around. Answer the questions by writing comments into the program. Remember that you have to hand in a working program at the end!


Hand in Name_StudentID_HW2-3a.py (or Name_StudentID_HW2-3.py) by sharing the files with PolyUCOMP1D04@gmail.com.

Note: Before you turn in your Python files, make sure they run without any errors(Save your Python file. Then select Run > Run Module or hit F5 on your keyboard)! If nothing appears in the Shell, don't worry as long as no red error messages appear. If they don't run, i.e. if red stuff starts appearing in the shell, points will be taken off!