#program to append data to a text file #if the file does not exist, it will be created birdFile = open("birdFile","a") print("This program lets you enter records to a file called birdFile.") print("If the file doesn't exist, it will be created.") numRecs = int(input("How many records do you want to enter? ")) for n in range (numRecs): birdName = input("Enter bird name: ") birdsSeen = input("Enter total number of birds seen: ") birdFile.write(birdName+","+birdsSeen+"\n") birdFile.close() birdFile = open("birdFile", "r") print("\nthe file has been closed and reopened for reading\n") wholefile = birdFile.read() print(wholefile) birdFile.close() # Read the file record by record # and calculate the total number of birds observed birdFile = open("birdFile", "r") totalBirdsSeen=0 for n in range (9): birdRec = birdFile.readline() field = birdRec.split(",") birdsSeen = int(field[1]) totalBirdsSeen = totalBirdsSeen + birdsSeen print("Total birds seen ", totalBirdsSeen)