QuestionQuestion

New Concepts to be applied for the assignment

Traversing a 2D list

Accessing elements in a list

Finding and replacing list elements

Description:

In order to get credit 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.

You will get the starting code for the two functions that you need to implement:

    def count(world):
       print("Counting number of occurances of a character")
       number = 0
       element = input("Enter character: ")
       # Insert your answer here
       return(element,number)

    Description of Count():

       Input/parameter/argument: a reference to a 2D list (already randomly initialized)
       Return value: an integer and string entered by the user
       The function will search through the list and count the number of occurrences of the character (single character String) entered by the user. This is the value returned by the function.
       The return values will be used by the start() function to show the user the number of occurances of this character:

       element,number = count(world)
       print("# occurances of %s=%d" %(element,number))

    def clean(world):
       print("Scooping the poop")
       # Insert your answer here

    Description of Clean():

       Input/parameter/argument: a reference to a 2D list (already randomly initialized)
       Return value: None
       The function will find and replace all occurances of the 'poop' character (POOP = "O") with the 'cleaned' character (CLEANED = ".")
       Note: that in the start() function after returning from clean() the 'world' list will be displayed again so the user can see the updated world.

You can still practice applying good style in your solution (e.g. using the predefined named constants such as 'CLEANED' rather than directly using an unnamed constant '.') as well as writing documentation.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import random

SIZE = 4
EMPTY = " "
PERSON = "P"
PET = "T"
POOP = "O"
ERROR = "!"
CLEANED = "."

'''
Students write
'''
# clean()
# @arg(world: a reference to a 2D list of Strings of length one)
# @return(none)
def clean(world):
    print("Scooping the poop")
    for i in range(len(world)):
       for j in range(len(world[i])):
            if world[i][j] == POOP:
                world[i][j] = CLEANED

'''
Students write
'''
# count()
# @arg(world: a reference to a 2D lis...
$40.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats