Advertisement
horozov86

Memory Game_While_True

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