Advertisement
GeorgiLukanov87

memory_game_exam_100/100

Jun 22nd, 2022
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. numbers = input().split()
  2. command = input()
  3. moves = 0
  4. no_match = True
  5.  
  6. while not command == 'end':
  7.     command = command.split()
  8.     moves += 1
  9.     index1 = int(command[0])
  10.     index2 = int(command[1])
  11.  
  12.     if index1 == index2 or index1 < 0 or index2 < 0 or index1 >= (len(numbers)) or index2 >= (len(numbers)):
  13.         print("Invalid input! Adding additional elements to the board")
  14.         middle = len(numbers)//2
  15.         numbers.insert(middle, f"-{moves}a")
  16.         numbers.insert(middle, f"-{moves}a")
  17.         command = input()
  18.         continue
  19.  
  20.     for twins in range(len(numbers)):
  21.         no_match = True
  22.         if numbers[index1] == numbers[index2]:
  23.             if index1 < index2:
  24.                 x2 = numbers.pop(int(index2))
  25.                 x1 = numbers.pop(int(index1))
  26.             else:
  27.                 x1 = numbers.pop(int(index1))
  28.                 x2 = numbers.pop(int(index2))
  29.             print(f"Congrats! You have found matching elements - {x1}!")
  30.             no_match = False
  31.             break
  32.            
  33.     if no_match:
  34.         print('Try again!')
  35.  
  36.     if len(numbers) == 0:
  37.         print(f"You have won in {moves} turns!")
  38.         break
  39.  
  40.     command = input()
  41.  
  42. if len(numbers) > 0:
  43.     print("Sorry you lose :(")
  44.     print(f"{' '.join(numbers)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement