Advertisement
Darlexbg

03. Legendary items

Oct 12th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. materials = {"shards": 0, "fragments": 0, "motes": 0}
  2. junk = {}
  3. legendary_item = ''
  4. is_collected = False
  5.  
  6. while materials["shards"] < 250 and materials["fragments"] < 250 and materials["motes"] < 250:
  7.     data = input().lower()
  8.     tokens = data.split(' ')
  9.  
  10.     for i in range(0, len(tokens), 2):
  11.         if materials["shards"] >= 250 or materials["fragments"] >= 250 or materials["motes"] >= 250:
  12.             is_collected = True
  13.             break
  14.         quantity = int(tokens[i])
  15.         material = tokens[i + 1]
  16.  
  17.         if material == "shards" or material == "fragments" or material == "motes":
  18.             materials[material] += quantity
  19.         else:
  20.             if material not in junk:
  21.                 junk[material] = 0
  22.             junk[material] += quantity
  23.     if is_collected:
  24.         break
  25.  
  26. if materials["shards"] >= 250:
  27.     legendary_item = 'Shadowmourne'
  28.     materials["shards"] -= 250
  29. elif materials["fragments"] >= 250:
  30.     legendary_item = 'Valanyr'
  31.     materials["fragments"] -= 250
  32. elif materials["motes"] >= 250:
  33.     legendary_item = 'Dragonwrath'
  34.     materials["motes"] -= 250
  35.  
  36. print(f"{legendary_item} obtained!")
  37.  
  38. for key, value in sorted(materials.items(), key=lambda item: (-item[1], item[0])):
  39.     print(f'{key}: {value}')
  40. for key, value in sorted(junk.items(), key=lambda item: (item[0])):
  41.     print(f'{key}: {value}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement