Westonci.ca is the best place to get answers to your questions, provided by a community of experienced and knowledgeable experts. Get immediate and reliable answers to your questions from a community of experienced experts on our platform. Discover detailed answers to your questions from a wide network of experts on our comprehensive Q&A platform.
Sagot :
The program based on the information given is illustrated below.
How to illustrate the program?
It should be noted that a computer program is a set of instructions in a programming language for the computer to execute.
Based on the information, the program is illustrated thus:
Code:
import pickle
#function to read birds data
def readBirdsData():
try:
birdsFile = open("birdsData","rb")
birdWatcher = pickle.load(birdsFile)
birdsFile.close()
birdWatcher ={}
except EOFError:
birdWatcher ={}
return birdWatcher
#function to write the data into file using pickle
def writeBirdsData(birdWatcher):
if birdWatcher == {} :
return
sorted(birdWatcher)
birdsFile = open("birdsData","ab")
pickle.dump(birdWatcher,birdsFile)
birdsFile.close()
#function to display birds data in sorted order
def displayBirdsData(birdWatcher):
print("Name\t\tCount")
print("========\t===========")
for key in sorted(birdWatcher.keys()):
print("{}\t\t{}".format(key,birdWatcher[key]))
#main function
def main():
birdWatcher = readBirdsData()
print("Bird Counter Program")
print ("\nEnter 'x' to exit\n")
name = input("Enter name of bird: ")
while True:
#break the loop if x is entered
if name == 'x':
#if the name exists in dictionary then increase the value
if the name in birdWatcher.keys():
birdWatcher[name] = birdWatcher[name] + 1
else:
#dd it otherwise
birdWatcher[name] = 1
name = input("Enter name of bird: ")
displayBirdsData(birdWatcher)
writeBirdsData(birdWatcher)
#driver code
if __nam__ == '__main__':
main()
Learn more about programs on:
https://brainly.com/question/26642771
#SPJ1
Thank you for your visit. We're dedicated to helping you find the information you need, whenever you need it. We appreciate your time. Please come back anytime for the latest information and answers to your questions. We're glad you visited Westonci.ca. Return anytime for updated answers from our knowledgeable team.