fruit_colours = { "Apple": "Red", "Raspberry": "Red", "Strawberry": "Red", "Orange": "Orange", "Banana": "Yellow", "Lemon": "Yellow", "Pineapple": "Yellow", "Avocado": "Green", "Lime": "Green", "Melon": "Green", "Pear": "Green", "Blueberry": "Blue", "Huckleberry": "Blue", "Plum": "Purple", "Grape": "Purple", "Maquiberry": "Purple" } def colour_of_fruit(fruit: str) -> str: """Returns the color of given fruit.""" try: return fruit_colours[fruit] except: return "Not a fruit!"
- fruit_colours = {
"Red": ("Apple", "Raspberry", "Strawberry"),"Orange": ("Orange",),"Yellow": ("Banana", "Lemon", "Pineapple"),"Green": ("Avocado", "Lime", "Melon", "Pear"),"Blue": ("Blueberry", "Huckleberry"),"Purple": ("Plum", "Grape", "Maquiberry")- "Apple": "Red", "Raspberry": "Red", "Strawberry": "Red",
- "Orange": "Orange",
- "Banana": "Yellow", "Lemon": "Yellow", "Pineapple": "Yellow",
- "Avocado": "Green", "Lime": "Green", "Melon": "Green",
- "Pear": "Green",
- "Blueberry": "Blue", "Huckleberry": "Blue",
- "Plum": "Purple", "Grape": "Purple", "Maquiberry": "Purple"
- }
- def colour_of_fruit(fruit: str) -> str:
- """Returns the color of given fruit."""
for color, fruits in fruit_colours.items():if fruit in fruits: return colorreturn "Not a fruit!"- try:
- return fruit_colours[fruit]
- except:
- return "Not a fruit!"