Advertisement
horozov86

Memory Game

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