yordan_yordanov

Memory cards

Oct 30th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. def play_round(cards, i_1, i_2, round_num):
  2. if i_1 == i_2 or i_1 not in range(len(cards)) or i_2 not in range(len(cards)):
  3. print(f"Invalid input! Adding additional elements to the board")
  4. card = f"-{round_num}a"
  5. middle = len(cards) // 2
  6. cards.insert(middle, card)
  7. cards.insert(middle + 1, card)
  8. return cards
  9.  
  10. if cards[index_1] == cards[index_2]:
  11. element = cards[index_1]
  12. print(f"Congrats! You have found matching elements - {element}!")
  13. cards.remove(element)
  14. cards.remove(element)
  15. return cards
  16.  
  17. print(f"Try again!")
  18. return cards
  19.  
  20.  
  21.  
  22. memory_cards = input().split()
  23. command = input()
  24. counter = 0
  25.  
  26. while not command == 'end':
  27. index_1, index_2 = list(map(int, command.split()))
  28. counter += 1
  29. memory_cards = play_round(memory_cards, index_1, index_2, counter)
  30. if len(memory_cards) == 0:
  31. print(f"You have won in {counter} turns!")
  32. break
  33. command = input()
  34.  
  35. if len(memory_cards) > 0:
  36. print(f"Sorry you lose :(")
  37. print(' '.join(memory_cards))
  38.  
Advertisement
Add Comment
Please, Sign In to add comment