Advertisement
Arksiana

3. Memory game

Nov 11th, 2020
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. elements = input().split()
  2.  
  3. moves = 0
  4. command = input()
  5. while not command == 'end':
  6.  
  7.     arg = command.split()
  8.     index_1 = int(arg[0])
  9.     index_2 = int(arg[1])
  10.     moves += 1
  11.     if 0 <= index_1 < len(elements) and 0 <= index_2 < len(elements):
  12.         value_1 = elements[index_1]
  13.         value_2 = elements[index_2]
  14.         if value_1 == value_2:
  15.             print(f"Congrats! You have found matching elements - {value_1}!")
  16.             elements.remove(value_1)
  17.             elements.remove(value_2)
  18.         else:
  19.             print('Try again!')
  20.     else:
  21.         print("Invalid input! Adding additional elements to the board")
  22.         middle = int(len(elements) / 2)
  23.         for el in range(moves):
  24.             elements.insert(middle, f"-{str(moves)}a")
  25.  
  26.     if len(elements) == 0:
  27.         print(f"You have won in {moves} turns!")
  28.         break
  29.  
  30.     command = input()
  31.  
  32. if len(elements) != 0:
  33.     print("Sorry you lose :(")
  34.     print(" ".join(elements))
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement