Moglibyście mi pomóc w napisaniu tych funkcji ?
Mam taki słownik:
inv = {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12}
Funkcja 1:
krok3.jpg
Zrobiłem taki kod, ale brakuje sortowania:
def print_table(inventory, order):
z = 0
print("Inventory:")
print()
print("count item name")
print("-" * 18)
#if order == "count,desc":
# [value for (key, value) in sorted(inventory.items())]
for key, value in inventory.items():
print('{:>4} {:>13}'.format(value, key))
z += value
print("-" * 18)
print("Total number of items: " + str(z))
Funkcja 2:
krok4.png --> plik do tego: test_inventory.csv
- krok3.jpg (226 KB) - ściągnięć: 102
- krok4.png (66 KB) - ściągnięć: 78
- test_inventory.csv (0 KB) - ściągnięć: 182