To the faculty page of James Tam | Return to the course web page |
Due at 4 PM. For assignment due dates see the main schedule on the course webpage.
Only new concepts that need to be applied in the assignment are listed, concepts previously applied in other assignments may need to used in the implementation of your solution.
Augment the existing program so that it will 'clean' the simulated world (4x4 list) of 'poop'. It will also [count] and display the number of occurrences of a user-specified string. Finally the user can specify the part of the world that will be included in the cleaning and the counting via [end point of the process]. For instance, the user can opt to only clean/count in the range from the first element (0,0) to the 2nd row and 3rd column (1,2). Any other instances outside that range will not be counted/cleaned. As you can see in the outline below the counting occurs before the cleaning.
In order to get credit for this assignment you must use the starting code ("map_starting.py"). The starting code will randomly populate a 4x4 list and display the current state. Because the initialization is random you will get a different pattern each time that you run the program so your program must work regardless of the starting pattern.
Here is an outline of the entire program:
def clean(world,endRow,endColumn):
# You must implement (it's largely empty)def count(world,endRow,endColumn):
# Randomly generates an 'occupant' for a location in the world
# You must augment
def createElement():
# It's been pre-written for you :D# Creates the SIZExSIZE world (SIZE = a named constant). Randomly populates it with the
# return values from function createElement
def createWorld():
# It's been pre-written for you :Ddef getEndPoint():
# You must implement from scratch# Shows the elements of the world. All the elements in a row will appear on the same line.
def start():
def display(world):
# It's been pre-written for you :D
world = createWorld() # Randomly generate world using the above two functions: createWorld and createElement
display(world)
endRow,endColumn = getEndPoint() # Get the last (row, column) on which the clean and count operations will affect
element,number = count(world) # Count # instances (in the world) of a user entered characterprint("# occurrences of %s=%d" %(element,number))
clean(world) # Remove the "undesired bio-matter debris" from the world
display(world) # Show again the 'cleaned' worldstart()
Below are the additional details of the three functions you are to implement for this assignment: count(), clean() and getEndPoint():
must return two numbers in the range from 0 - 3.(Worth 1.0 GPA) Description of getEndPoint():
There is no starting code, you must implement this function from scratch.
- Input/parameter/argument: None
- Return value: two integers.
- The function will repeatedly prompt the user for the 'end point' (last included row and column) on which the count and the clean operations will occur.
- For instance if the user enters a row of 3 and a column of 3 then the two operations will occur from row 0 to row 3 and from column 0 to column 3 (i.e. the whole list).
- If the user enters a row of 0 and a column of 0 then count and cleaning will only occur on the first element.
- The program should indicate to the user the valid range of values that can be entered (0-3) and repeatedly prompt for a value so long as a value outside this range is entered. That is this function
Count of 'T' in the example simulated world (shown above)
# Starting code
def count(world,endRow,endColumn):
print("Counting number of
occurrences of a character")
number = 0
element = input("Enter character: ")
# Insert your answer here for counting
occurrences
return(element,number)
Input/parameter/argument: a reference to a 2D list (already randomly initialized), the index of the (row, column) on which the count will be conducted. (For a 4x4 list the indices range from 0 to 3 for the row/columns).
element,number = count(world,endRow,endColumn)
print("# occurrences of %s=%d" %(element,number))
Cleaning the 'poop' from the example simulated world
# Starting code
def clean(world,endRow,endColumn):
print("Scooping the poop")
# Insert your answer here for removing instances of the 'poop'
character
Note: you can be awarded credit for each of the 3 functions regardless of whether the other functions were complete or correct. For instance you can be awarded 1.0 GPA for just writing a function that properly gets and returns the end point from the user. Conversely if your function for getting the end point wasn't correct but the other functions were complete and correct (i.e. the count and cleaning always occurred on the whole list) then a maximum 3.0 GPA could be awarded for the assignment.
There is a sample run of my solution ("output.txt").
Program functionality (implementing working program features)
Test your program: Because the assignment description (along with required features) is posted ahead of time if you test your program thoroughly before submitting the final version then you should get a pretty clear idea of "how you will do".
Although it won't affect your grade for mini-assignments you should still practice applying good style in your solution as well as writing documentation. It will keep your skills for the full assignments (when you will be graded on these things) and get you used to having good habits.
Naming the file containing your program: You must save your program in a file called "files2.py". Failing to use this exact name will affect your grade (-0.2 GPA).
Questions or concerns about grades after they have been released: Assignments will be marked by your tutorial instructor (the "Teaching Assistant" or "TA") for your tutorial section. When you have questions about marking this is the first person that you should be directing your questions towards. If you still have question after you have talked to your TA, then you can talk to your course (lecture) instructor but please indicate in your email that you first contacted your TA before going into your concerns.
Late assignments or components of assignments/Assignment extensions: Normally due dates are strict and extensions require documentation. Due to the likelihood of widespread Covid related illnesses late penalties will not be applied this semester. But if you do submit something after the due date/time then you should email your marker (TA in the tutorial that you are officially registered) so that person will know to look for it in D2L. Also if are submitting too many graded components late however this doesn't bode well for your performance in this course so you may be referred to the associate dean of undergraduate students (faculty of science) and she may contact you regarding your course work.
Assignments must reflect individual work; group work is not allowed in this class nor can you copy the work of others. Some "do nots" for your solution: don't publically post it, don't email it out, don't show it to other students. For more detailed information as to what constitutes academic misconduct (i.e., cheating) for this course please read the following [link].
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 you submit your assignment with enough time before it comes due for you to do a check). If don't check and there were problems with the submission then you should not expect that you can "learn your lesson" and simply resubmit.
Submission received: |
On time |
Hours late : >0 and <=24 |
Hours late: >24 and <=48 |
Penalty: |
None |
-1 GPA |
-No credit (not accepted) |
Unless otherwise told you are to write the code yourself and not use any pre-created functions (or methods). For most assignments the usual acceptable functions include: print(), input() and the 'conversion' functions such as int(), float(), str(). Look at the particular assignment description for a list of other functions/methods that you are allowed to use and still get credit in an assignment submission. If it's not listed then you should assume that you won't be able use the function and still be awarded credit.