Advertisement
go6odn28

3_memory_game...

Feb 17th, 2024
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. def check_indexes(user_list, ind_list, non_valid_input, move):
  2.     for value in ind_list:
  3.         if (0 > int(value) or int(value) > len(user_list) - 1) or len(set(ind_list)) == 1:
  4.             user_list.insert(int(len(user_list) / 2), f'-{move}a')
  5.             user_list.insert(int(len(user_list) / 2), f'-{move}a')
  6.             print('Invalid input! Adding additional elements to the board')
  7.             non_valid_input = True
  8.             break
  9.     return non_valid_input
  10.  
  11.  
  12. def checks_found_element(user_list1, indexes_list1):
  13.     if user_list1[int(indexes_list1[0])] == user_list1[int(indexes_list1[1])]:
  14.         symbol = user_list1[int(indexes_list1[0])]
  15.         print(f'Congrats! You have found matching elements - {symbol}!')
  16.         for index in range(len(indexes_list1)):
  17.             command.remove(symbol)
  18.     else:
  19.         print('Try again!')
  20.     return user_list1   ################ change
  21.  
  22.  
  23. def check_equal_pair(user_list, indexes_list):
  24.     current_move = 0
  25.     while indexes_list != ['end']:
  26.         current_move += 1
  27.         invalid_input = False
  28.         invalid_input = check_indexes(command, indexes_list, invalid_input, current_move)
  29.         if invalid_input:
  30.             indexes_list = input().split()  ########   change
  31.             continue
  32.         checks_found_element(user_list, indexes_list)   ########   change
  33.         if len(user_list) == 0:
  34.             print(f'You have won in {current_move} turns!')
  35.             break
  36.         indexes_list = input().split()
  37.     return user_list
  38.  
  39.  
  40. command = input().split()
  41. list_indexes = input().split()
  42.  
  43. ########   change
  44. command = check_equal_pair(command, list_indexes)
  45.  
  46. if len(command) != 0:
  47.     print('Sorry you lose :(')
  48.     print(*command)
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement