Untitled
Anonymous
plain_text
05/08/2023 1:37 AM
760 B
23
Indexable
def id_to_fruit(fruit_id: int, fruits: set[str]) -> str:
idx = 0
print(fruits)
for fruit in fruits:
print(idx, fruit_id, fruit)
if idx == fruit_id:
print(idx, end=' ')
return fruit
idx += 1
raise RuntimeError(f"Fruit with id {fruit_id} does not exist")
name1 = id_to_fruit(1, {"apple", "orange", "melon", "kiwi", "strawberry"})
name3 = id_to_fruit(3, {"apple", "orange", "melon", "kiwi", "strawberry"})
name4 = id_to_fruit(4, {"apple", "orange", "melon", "kiwi", "strawberry"})
print(name1, name3, name4)Editor is loading...