def SubChoiceStatistics(self, p): choice: str = "" choice = ToolBox.InputAny("Choose an option: ") print() if choice == "1": for habitat in p.arkOne.GetHabitats(): habitat.SumAnimals() ToolBox.WriteBlue(habitat.HabitatName) count: int = 0 for items in habitat.AnimalDict: count += items.Value print(" has " + count + " amimals") print() ToolBox.InputAny("Press any key to continue...") elif choice == "2": for habitat in p.arkOne.GetHabitats(): habitat.SumAnimals() ToolBox.WriteLineBlue(habitat.HabitatName.ToUpper() + ":") for items in habitat.AnimalDict: print(items.Keys + " : ") print(items.Value) ToolBox.InputAny("Press any key to continue...") elif choice == "0": return False else: ToolBox.WriteLineRed("Wrong option!") return True
def SubChoiceHabitat(self, p): choice: str = ToolBox.InputAny("Choose an option: ") print() if choice == "1": # Creating new habitat try: newName: str = ToolBox.InputAny( "The name of the new Habitat?: ") if p.arkOne.IsHabitatExist(newName): raise HabitatIsExistException p.arkOne.CreatingAHabitat(newName) ToolBox.WriteLineGreen("Tha habitat has been built.") except HabitatIsExistException: ToolBox.WriteLineRed("This Habitat is already exist") time.Sleep(1500) elif choice == "2": # Displaying Habitats for habitat in p.arkOne.GetHabitats(): ToolBox.WriteBlue(habitat.HabitatName + ": ") print(habitat.AnimalList.Count.ToString() + " animals live in this Habitat.") ToolBox.InputAny("Press any key to continue...") elif choice == "3": # Renaming a Habitat try: habitatName: str = ToolBox.InputAny( "The name of the Habitat?: ") newName: str = ToolBox.InputAny( "The new name of the Habitat?: ") if p.arkOne.IsHabitatExist(newName): raise HabitatIsExistException() habitats = p.arkOne.GetHabitats() for habitat in habitats: if not p.arkOne.IsHabitatExist(newName): habitat.SetHabitatName(newName) ToolBox.WriteLineGreen("The Habitat has been renamed.") except HabitatNotExistException: ToolBox.WriteLineRed("This Habitat is not exist") except HabitatIsExistException: ToolBox.WriteLineRed("This Habitat is already exist") time.sleep(1500) elif choice == "4": # Deleting a Habitat try: p.arkOne.RemovingAHabitat( ToolBox.InputAny("The name of the habitat?: ")) ToolBox.WriteLineGreen("The Habitat has been demolished.") except HabitatNotExistException: ToolBox.WriteLineRed("This Habitat is not exist") except NotEmptyHabitatException: ToolBox.WriteLineRed( "You can not demolish because animals live there") time.sleep(1500) elif choice == "0": # Back to main menu return False else: ToolBox.WriteLineRed("Wrong option!") return True