# File: moWeKennel.py # Author: Dr. Gibson # Date: 10/3/2016 # Section: N/A # E-mail: k.gibson@umbc.edu # Description: # This code is similar to what we worked on in class. # # This file contains python code that simulates a few # list-based tasks that kennel assistants might perform. def main(): # initialize the list of kennel pens with the dogs they contain kennelPens = ["Alaskan Klee Kai", "Beagle", "Chow Chow", "Doberman", "English Bulldog"] # first assistant only needs info about what the kennels contains, # so we use a for loop that goes over the contents of our list print("All of the dogs in the kennel:") print("------------------------------") for k in kennelPens: print(k) # second assistant needs to know their pen numbers as well, # so we use a for loop that goes over the INDEXES of our list print() # print empty line print("Location of dogs in the kennel:") print("-------------------------------") for i in range(len(kennelPens)): print("The dog in pen number", i, "is a", kennelPens[i]) # NOTE: range() goes on the outside, because len() will # give us an integer (in this case, 5) and range() can # then use that to generate the list [0, 1, 2, 3, 4] # which are the different indexes of kennelPens items # third assistant needs to be able to CHANGE the contents of # kennelPens list, so we can't just iterate over the contents # instead, we must again use a for loop over the INDEXES print() # print empty line print("Dogs picked up, German Shepherds dropped off:") print("---------------------------------------------") for i in range(len(kennelPens)): originalDog = kennelPens[i] kennelPens[i] = "German Shepherd" # overwrite the old contents print("The", originalDog, "was picked up from pen", i) # NOTE: iterating over the contents uses the loop variable to # copy each list element, meaning that any changes made # to the loop variable don't carry over to the list itself # and finally, let's just check the list one last time; since # we're not changing anything, iterating over the contents is fine print() # print empty line print("At the end of the day:") print("----------------------") for k in kennelPens: print(k) main()