Advertisement
yordan_yordanov

Crafting

Nov 7th, 2020
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. # SOLUTION 1
  2. parts = input().split("|")
  3. command = input().split()
  4.  
  5. even = []
  6. odd = []
  7.  
  8. while not command[0] == "Done":
  9. if command[0] == "Move":
  10.  
  11. if command[1] == "Left":
  12. if 0 < int(command[2]) < len(parts):
  13. parts[int(command[2])], parts[int(command[2]) - 1] = parts[int(command[2]) - 1], parts[int(command[2])]
  14. elif command[1] == "Right":
  15. if 0 <= int(command[2]) < len(parts) - 1:
  16. parts[int(command[2])], parts[int(command[2]) + 1] = parts[int(command[2]) + 1], parts[int(command[2])]
  17.  
  18. elif command[0] == "Check Even":
  19. for index in range(len(parts)):
  20. if index % 2 == 0:
  21. even.append(parts(int(index)))
  22. print(" ".join(even))
  23. even = []
  24.  
  25. elif command[0] == "Check Odd":
  26. for index in range(len(parts)):
  27. if index % 2 == 1:
  28. odd.append(parts(int(index)))
  29. print(" ".join(odd))
  30. odd = []
  31.  
  32. command = input().split()
  33.  
  34. weapon = "".join(parts)
  35. print(f"You crafted {weapon}!")
  36.  
  37. # SOLUTION 2
  38. parts = input().split("|")
  39. command = input().split()
  40.  
  41. even_indices = list()
  42. odd_indices = list()
  43.  
  44. while not command[0] == "Done":
  45. if command[0] == "Move":
  46. if command[1] == "Left":
  47. if 0 < int(command[2]) < len(parts):
  48. parts[int(command[2])], parts[int(command[2]) - 1] = parts[int(command[2]) - 1], parts[int(command[2])]
  49. elif command[1] == "Right":
  50. if 0 <= int(command[2]) < len(parts) - 1:
  51. parts[int(command[2])], parts[int(command[2]) + 1] = parts[int(command[2]) + 1], parts[int(command[2])]
  52.  
  53. elif command[0] == "Check":
  54. if command[1] == "Even":
  55. for index in range(len(parts)):
  56. if index % 2 == 0:
  57. even_indices.append(parts[int(index)])
  58. print(" ".join(even_indices))
  59. even_indices = []
  60.  
  61. if command[1] == "Odd":
  62. for index in range(len(parts)):
  63. if index % 2 == 1:
  64. odd_indices.append(parts[int(index)])
  65. print(" ".join(odd_indices))
  66. odd_indices = []
  67.  
  68. command = input().split()
  69.  
  70. weapon = "".join(parts)
  71. print(f"You crafted {weapon}!")
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement