import random
debug = False
yBird = {}
yLocation = {}
#....... XXXXXXXXXX1 ...........................
def addBirdSighting(day, birdSighting, ledger):
'''
Add a bird sighting to the cu
ent day in the ledge
birdSighting - the sighting to add
ledger - the ledger to update
'''
return ledge
#....... XXXXXXXXXX2 ...........................
def birdsSeenEachDay(ledger):
'''
Compute the number of birds within the ledger for each day
ledger - the ledger to analyze
returns a list of counts, one for each day
'''
counts = []
return counts
#....... XXXXXXXXXX3 ...........................
def printLedger(ledger):
'''
Print the sighting within the ledger, separated by the day
ledger - the ledger to print
'''
#....... XXXXXXXXXX4 ...........................
# Don't forget to fill the byBird dictionary in addBirdSighting!
def numberOfSightingsFor(bird, ledger):
'''
Determine how many times the bird provided was sighted on the ledger (using a dictionary)
bird - the bird to count
ledger - the ledger to search
returns the number of sightings for this bird in this ledge
'''
return 0
#....... XXXXXXXXXX5 ...........................
# Don't forget to fill the byLocation dictionary in addBirdSighting!
def allBirdsSpottedAt(location, ledger):
'''
Identify all unique species of birds spotted at the provided location and their count
location - the location to query
ledger - the ledger to query
returns a dictionary where the key is the bird and the value is the count at that location
'''
return {}
#=============================================================================
# Test code below DO NOT MODIFY
BIRDS = ["Finch", "Robin", "Hummingbird", "Crow", "Eagle", "Hawk", "Cardinal", "Vulture", "Phoenix", "Spa
ow"]
LOCATIONS = ["Park", "Backyard", "Skyscraper", "Forest", "Jungle", "Roadside", "Cage", "Sky", "Desert"]
TIME_OF_DAY = ["6-10AM", "10AM-2PM", "2-6PM", "6-10PM", "10PM-2AM", "2-6AM"]
irdCount = [0] * len(BIRDS)
TEST_INDEX = 3 # Just one selected location, no specific choice
locationTest = {}
def generateSighting():
birdIndex = random.randrange(len(BIRDS))
birdCount[birdIndex] = birdCount[birdIndex] + 1
locationIndex = random.randrange(len(LOCATIONS))
if locationIndex == TEST_INDEX:
XXXXXXXXXXif BIRDS[birdIndex] in locationTest:
XXXXXXXXXXlocationTest[BIRDS[birdIndex]] = locationTest[BIRDS[birdIndex]] + 1
XXXXXXXXXXelse:
XXXXXXXXXXlocationTest[BIRDS[birdIndex]] = 1
return BIRDS[birdIndex], \
XXXXXXXXXXLOCATIONS[locationIndex], \
XXXXXXXXXXTIME_OF_DAY[random.randrange(len(TIME_OF_DAY))]
def testLedger():
ledger = {}
dayCount = []
numberOfDays = random.randint(10, 20)
if debug: print("The test cases will generate", numberOfDays, "days")
for day in range(numberOfDays):
XXXXXXXXXXnumberOfSightings = random.randint(10, 50)
XXXXXXXXXXdayCount.append(numberOfSightings)
XXXXXXXXXXdayName = "Day " + str(day + 1)
XXXXXXXXXXif debug: print(dayName, "will contain", numberOfSightings, "sightings")
XXXXXXXXXXfor count in range(numberOfSightings):
XXXXXXXXXXsighting = generateSighting()
XXXXXXXXXXaddBirdSighting(dayName, sighting, ledger)
counts = birdsSeenEachDay(ledger)
if counts != dayCount:
XXXXXXXXXXprint("birdsSeenEachDay() Failed: Your code returned", counts, "but I expected", dayCount)
else:
XXXXXXXXXXprint("birdsSeenEachDay() Passed!")
return ledge
def testNumberOfSightingsFor(ledger):
success = True
for index, bird in enumerate(BIRDS):
XXXXXXXXXXactual = numberOfSightingsFor(bird, ledger)
XXXXXXXXXXif actual != birdCount[index]:
XXXXXXXXXXsuccess = False
XXXXXXXXXXprint("testNumberOfSightingsFor() Failed: Your code reported", actual, "but I expected", birdCount[index], "for", bird)
actual = numberOfSightingsFor("Ostrich", ledger)
if actual != 0:
XXXXXXXXXXprint("testNumberOfSightingsFor() Failed: Your code reported", actual, "but I expected 0 for Ostrich")
return success
def testAllBirdsSpottedAt(ledger):
success = True
locationDetails = allBirdsSpottedAt(LOCATIONS[TEST_INDEX], ledger)
if locationDetails != locationTest:
XXXXXXXXXXsuccess = False
XXXXXXXXXXprint("testAllBirdsSpottedAt Failed!: Your code reported", locationDetails, "but I expected", locationTest, "at", LOCATIONS[TEST_INDEX])
actual = allBirdsSpottedAt("My House", ledger)
if len(actual) != 0:
XXXXXXXXXXsuccess = False
XXXXXXXXXXprint("testAllBirdsSpottedAt Failed!: Your code reported", actual, "but I expected no sightings at the empty value of My House")
return success
# Only run this code below if this is called as the main, not imported
if __name__ == '__main__':
ledger = testLedger()
if testNumberOfSightingsFor(ledger):
XXXXXXXXXXprint("numberOfSightingsFor() Passed!")
if testAllBirdsSpottedAt(ledger):
XXXXXXXXXXprint("testAllBirdsSpottedAt() Passed!")
import random
debug = False
#...... XXXXXXXXXX1 .................................
def generateKey():
'''
Generate the cipher keys
return a dictionary of the encryption keys
'''
cipher = {}
return ciphe
#...... XXXXXXXXXX2 .................................
def generateDecryptKey(key):
'''
Generate the key required to decrypt given the encryption key
key - the encryption key
returns a dictionary of the decryption keys
'''
decryptKey = {}
return decryptKey
#...... XXXXXXXXXX3 .................................
def encrypt(phrase, key):
'''
Encrypt the phrase
phrase - the phrase to encrypt
key - the key to use
returns the encrypted key
'''
out = ""
return out
#...... XXXXXXXXXX4 .................................
def decrypt(phrase, key):
out = ""
return out
#==================================================
# Test code below this point DO NOT MODIFY
def generateAllLetters():
'''
Generate a list of every letter A-Z and a-z
returns the list of every lette
'''
allLetters = []
for letter in range(ord('A'), ord('Z') + 1):
XXXXXXXXXXallLetters.append(chr(letter))
for letter in range(ord('a'), ord('z') + 1):
XXXXXXXXXXallLetters.append(chr(letter))
return allLetters
TESTS = ["Simple", "HELLO PYTHON", "Simple Encryption in Python is Fun!",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"]
def testEncryptionKey():
encryptionKey = generateKey()
if len(encryptionKey) != 52:
XXXXXXXXXXprint("generateKey Failed: I expected the key to contain 52 entries, but it contained", len(encryptionKey))
return encryptionKey
def testDecryptionKey(encryptionKey):
decryptionKey = generateDecryptKey(encryptionKey)
for key in decryptionKey:
XXXXXXXXXXif key != encryptionKey[decryptionKey[key]]:
XXXXXXXXXXprint("generateDecryptKey() Failed: The values", decryptionKey[key], "and", key, "do not match in the encryption and decryption keys")
return decryptionKey
def testEncryption(encryptionKey, decryptionKey):
success = True
for phrase in TESTS: