zaxooooo

Fundamentals module Task 4

Feb 25th, 2021
663
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def check_index_is_valid(index, len_list):
  2.     if index in range(len_list):
  3.         return True
  4.     return False
  5.  
  6.  
  7. cards = input().split()
  8.  
  9. command = input()
  10.  
  11. number_of_rounds = 0
  12.  
  13. while not command == "end" and cards:
  14.     index_1, index_2 = command.split()
  15.     index_1 = int(index_1)
  16.     index_2 = int(index_2)
  17.  
  18.     number_of_rounds += 1
  19.  
  20.     if check_index_is_valid(index_1, len(cards)) and check_index_is_valid(index_2, len(cards)) and not index_1 == index_2:
  21.         el_1 = cards[index_1]
  22.         el_2 = cards[index_2]
  23.         if el_1 == el_2:
  24.             cards.remove(el_1)
  25.             cards.remove(el_2)
  26.             print(f"Congrats! You have found matching elements - {el_1}!")
  27.         else:
  28.             print("Try again!")
  29.     else:
  30.         element_to_add = f"-{number_of_rounds}a"
  31.         middle = len(cards) // 2
  32.         cards.insert(middle, element_to_add)
  33.         cards.insert(middle, element_to_add)
  34.         print("Invalid input! Adding additional elements to the board")
  35.  
  36.     command = input()
  37.  
  38. if not cards:
  39.     print(f"You have won in {number_of_rounds} turns!")
  40. else:
  41.     print("Sorry you lose :(")
  42.     print(' '.join(cards))
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×