Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_valid_index(lst, idx):
- return 0 <= idx < len(lst)
- def memory_game():
- elements = input().split()
- moves = 0
- while True:
- command = input()
- if command == "end":
- break
- indices_data = command.split()
- index_1, index_2 = int(indices_data[0]), int(indices_data[1])
- moves += 1
- if is_valid_index(elements, index_1) and is_valid_index(elements, index_2) and index_1 != index_2:
- if elements[index_1] == elements[index_2]:
- matching_element = elements[index_1]
- while matching_element in elements:
- elements.remove(matching_element)
- print(f"Congrats! You have found matching elements - {matching_element}!")
- else:
- print("Try again!")
- else:
- print("Invalid input! Adding additional elements to the board")
- index_middle_of_the_list = len(elements) // 2
- elements.insert(index_middle_of_the_list, f"-{moves}a")
- elements.insert(index_middle_of_the_list + 1, f"-{moves}a")
- if not elements:
- print(f"You have won in {moves} turns!")
- break
- if elements:
- print("Sorry you lose :(")
- print(*elements)
- memory_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement