Advertisement
snow27

Untitled

Nov 2nd, 2020
1,512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. sequence_of_elements = input().split()
  2. count_moves = 0
  3. command = input()
  4. while not command == "end":
  5.     count_moves += 1
  6.     index1 = int(command.split()[0])
  7.     index2 = int(command.split()[1])
  8.     if index1 == index2 or index1 < 0 or index2 < 0 or index1 >= len(sequence_of_elements) or index2 >= len(sequence_of_elements):
  9.         sequence_of_elements.insert(int(len(sequence_of_elements) / 2), f"-{str(count_moves)}a")
  10.         sequence_of_elements.insert(int(len(sequence_of_elements) / 2), f"-{str(count_moves)}a")
  11.         print("Invalid input! Adding additional elements to the board")
  12.     elif sequence_of_elements[index1] == sequence_of_elements[index2]:
  13.         print(f"Congrats! You have found matching elements - {sequence_of_elements[index1]}!")
  14.         x = sequence_of_elements.pop(index1)
  15.         sequence_of_elements.remove(x)
  16.     elif sequence_of_elements[index1] != sequence_of_elements[index2]:
  17.         print("Try again!")
  18.     if len(sequence_of_elements) == 0:
  19.         print(f"You have won in {count_moves} turns!")
  20.         break
  21.     command = input()
  22. if command == "end":
  23.     print("Sorry you lose :(\n"
  24.           f"{' '.join(sequence_of_elements)}")
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement