Advertisement
Guest User

Treasure Hunt

a guest
Feb 27th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. chest = input().split('|')
  2. counter = 0
  3.  
  4.  
  5. while True:
  6. text = input().split()
  7. command = text[0]
  8. if command == 'Yohoho!':
  9. break
  10. elif command == 'Loot':
  11. for item in text[1::]:
  12. if item not in chest:
  13. chest.insert(0, item)
  14. elif command == 'Drop':
  15. index = int(text[1])
  16. if 0 <= index < len(chest):
  17. chest.append(chest.pop(index))
  18. elif command == 'Steal':
  19. stolen = []
  20. count = int(text[1])
  21. if count <= len(chest):
  22. stolen = chest[-count ::]
  23. for i in range(count):
  24. chest.pop()
  25. else:
  26. stolen = chest.copy()
  27. chest.clear()
  28. print(', '.join(stolen))
  29. else:
  30. break
  31. if chest:
  32. credit = 0
  33. for item in chest:
  34. counter += len(item)
  35. credit = counter / len(chest)
  36. print(f'Average treasure gain: {credit:.2f} pirate credits.')
  37. else:
  38. print('Failed treasure hunt.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement