Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def try_match(index1, index2, list_of_elements):
- first_element = ''
- second_element = ''
- for index, element in enumerate(list_of_elements):
- if index == index1:
- first_element = element
- elif index == index2:
- second_element = element
- if first_element == second_element:
- list_of_elements.remove(first_element)
- list_of_elements.remove(second_element)
- print(f"Congrats! You have found matching elements - {first_element}!")
- else:
- print(f"Try again!")
- def invalid_index(moves, list_of_elements):
- first_half_of_list = len(list_of_elements) // 2
- for index, element in enumerate(list_of_elements):
- if index == first_half_of_list:
- list_of_elements.insert(index, f"-{moves}a")
- list_of_elements.insert(index + 1, f"-{moves}a")
- print(f"Invalid input! Adding additional elements to the board")
- def game_progress(list_of_elements):
- moves_counter = 0
- player_won = False
- while True:
- command = input()
- if command == 'end':
- break
- moves_counter += 1
- first_index, second_index = map(int, command.split())
- if first_index < 0 or first_index > len(sequence_of_elements) or second_index < 0 or second_index > len(
- sequence_of_elements) or first_index == second_index:
- invalid_index(moves_counter, sequence_of_elements)
- else:
- try_match(first_index, second_index, sequence_of_elements)
- if len(sequence_of_elements) == 0:
- player_won = True
- break
- if player_won:
- print(f"You have won in {moves_counter} turns!")
- else:
- print(f"Sorry you lose :(\n{' '.join(list_of_elements)}")
- sequence_of_elements = input().split()
- game_progress(sequence_of_elements)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement