Computer Science I for majors by James Tam

Return to the course web page

CPSC 231: Mini-Assignment 4A

Due Friday Nov 18 at 4 PM (JT's note: this mini-assignment may be more challenging to some students than previous ones, try to start it as soon as possible. You should start it well before starting Assignment 4 because developing a familiarity with these basic list operations will be helpful in the corresponding full assignment).

New Concepts to be applied for the assignment

Description:

To provide consistency and to speed up marking (as well as honing your experience at using pre-created code) you MUST use the starting code or your input and output must precisely match what you will see the starting code under: /home/231/assignments/mini_assignment4a/code. There is a sample output file of my solution under:  /home/231/assignments/mini_assignment4a/output.

The starting program initializes (via the randomize() function) a 2D 4x4list to random integer values between 0 - 4 (grade points). There is a function to display the list (display()). Write the code for three functions:

  1. countFails(): Takes the 2D list as an argument returns a count of the number of elements which are failing grade points (GPA = 0). (Worth 1.3 grade points)
  2. modify(): Takes the 2D list as an argument. It searches and replaces all instances of '0' grades with an exclamation mark '!'. (Worth 1.4 grade points)
  3. modifyElement(): Takes the 2D list as an argument as well as the (row/column) of the element to modify. The function will either: 1) change the list element at the specified location to a question mark '?'  2) if the location is outside the bounds of the list (in this case you can define 'in bounds" as row and column values 0 - 4, don't allow for negative indices) then display a suitable error message. (Worth 1.3 grade points)

Counting the number of failures (sample run)

Original list

1 4 2 2

4 1 0 0

4 2 0 0

0 2 0 4

Before modifications: # of failing grades 6

Modifying failing failing grades (sample run)

Modified list

1 4 2 2

4 1 ! !

4 2 ! !

! 2 ! 4

Modifying any list element (sample run)

Setting an element to '?'

Row value: 0

Column value: 0

? 1 4 !

2 3 4 !

! 1 2 1

1 4 2 3

[TA Marking spreadsheet]

Points to keep in mind:

  1. Due time: All assignments are due at 4 PM on the due dates listed on the course web page.  Late assignments or components of assignments will not be accepted for marking without approval for an extension beforehand. What you have submitted in D2L as of the due date is what will be marked.
  2. Extensions may be granted for reasonable cases by the course instructor with the receipt of the appropriate documentation (e.g., a doctor's note). Typical examples of reasonable cases for an extension include: illness or a death in the family. Cases where extensions will not be granted include situations that are typical of student life: having multiple due dates, work commitments etc. Tutorial instructors (TA's) will not be able to provide extension on their own and must receive permission from the course instructor first. (Note: Forgetting to hand your assignment or a component of your assignment in does not constitute a sufficient reason for handing your assignment late).
  3. Method of submission: You are to submit your assignment using D2L [help link]. Make sure that you [check the contents of your submitted files] (e.g., is the file okay or was it corrupted, is it the correct version etc.). It's your responsibility to do this! (Make sure that your submit your assignment with enough time before it comes due for you to do a check).
  4. Identifying information: All assignments should include contact information (full name and student ID number) at the very top of your program in the class where the 'main()' function/method resides.
  5. Collaboration: Assignments must reflect individual work, group work is not allowed in this class nor can you copy the work of others.  For more detailed information as to what constitutes academic misconduct (i.e., cheating) for this course please read the following [link].
  6. Execution: programs must run on the computer science network running Python 3.x. If you write you code in the lab and work remotely using a remote login program such as Putty or SSH. If you choose to install Python on your own computer then it is your responsibility to ensure that your program will run properly here. It's not recommended that you use an IDE for writing your programs but if you use one then make sure that you submit your program in the form of text ".py" file or files
  7. Use of pre-created Python libraries: unless otherwise told you are to write the code yourself and not use any pre-created functions from the Python libraries. For this assignment acceptable functions include: print(), input() and likely str().

D2L configuration:

Marking: