Advertisement
Maxim_01

Untitled

Jun 22nd, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. elements = input().split()
  2. moves = 0
  3. while True:
  4.     command = input()
  5.     if command == "end":
  6.         break
  7.     if len(elements) <= 0:
  8.         print(f"You have won in {moves} turns!")
  9.         break
  10.  
  11.     moves += 1
  12.     command = command.split()
  13.     first_index = int(command[0])
  14.     second_index = int(command[1])
  15.     if first_index == second_index or first_index > len(elements) or second_index > len(elements) \
  16.             or int(first_index) < 0 or int(second_index) < 0:
  17.         print("Invalid input! Adding additional elements to the board")
  18.         middle_of_elements = len(elements) / 2
  19.         frase = f"-{moves}a"
  20.         elements.insert(int(middle_of_elements), frase)
  21.         another_index = elements.index(frase)
  22.         elements.insert(another_index + 1, frase)
  23.     elif elements[first_index] == elements[second_index]:
  24.         print(f"Congrats! You have found matching elements - {elements[first_index]}!")
  25.         current_symbol = elements[first_index]
  26.  
  27.         elements.remove(current_symbol)
  28.         elements.remove(current_symbol)
  29.  
  30.  
  31.     elif elements[first_index] != elements[second_index]:
  32.         print("Try again!")
  33.  
  34. if len(elements) > 0:
  35.     print("Sorry you lose :(")
  36.     print((" ").join(elements))
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement