# --------------------------------------- # Computer Science # Program 13: Bird Targets # Your Name # Last Modified: # --------------------------------------- # A brief overview of the program. # --------------------------------------- # Your solution goes here ... # --------------------------------------- # Do not change anything below this line # --------------------------------------- def create_targets(filename): targets = {} file = open(filename, "r") for bird in file: birdlist = bird.strip().split(",") index = int(birdlist.pop(0)) targets[index] = [birdlist.pop(0)] # common name targets[index] += [birdlist.pop(0)] # scientific name targets[index] += [birdlist.pop(0)] # family targets[index] += [birdlist.pop(0)] # frequency of occurrence on eBird checklists file.close() return targets # --------------------------------------- def get_choice(low, high, message): legal_choice = False while not legal_choice: legal_choice = True answer = input(message) for character in answer: if character not in string.digits: legal_choice = False print("That is not a number, try again.") break if legal_choice: answer = int(answer) if (answer < low) or (answer > high): legal_choice = False print("That is not a valid choice, try again.") return answer # --------------------------------------- targets = create_targets("birddata.txt") choice = 0 while choice != 6: print_menu() choice = get_choice(1, 6, "Enter a menu option: ") if choice == 1: print_target_list(targets) elif choice == 2: name = input("Enter a bird name: ") name = name.capitalize() lookup_by_name(targets, name) elif choice == 3: number = get_choice(1, 100, "Enter a item number: ") lookup_by_number(targets, number) elif choice == 4: how_many_birds(targets) elif choice == 5: family = input("Enter a family name: ") how_many_in_family(targets, family) print("Thank you. Goodbye!")