Advertisement
pacho_the_python

Untitled

Feb 12th, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. numbers = input().split(" ")
  2.  
  3. command = input()
  4.  
  5. turns = 0
  6.  
  7. while True:
  8.     if command == "end":
  9.         break
  10.     turns += 1
  11.     nums = command.split(" ")
  12.     ind_one = int(nums[0])
  13.     ind_two = int(nums[1])
  14.  
  15.     if ind_one != ind_two and 0 <= ind_one <= len(numbers) and 0 <= ind_two <= len(numbers):
  16.         if numbers[ind_one] == numbers[ind_two]:
  17.             print(f"Congrats! You have found matching elements - {numbers[ind_one]}!")
  18.             x = numbers.pop(ind_one)
  19.             numbers.remove(x)
  20.         else:
  21.             print("Try again!")
  22.  
  23.     else:
  24.         print(f"Invalid input! Adding additional elements to the board")
  25.         mid = len(numbers) // 2
  26.         numbers.insert(mid, f"-{turns}a")
  27.         numbers.insert(mid, f"-{turns}a")
  28.  
  29.     if len(numbers) == 0:
  30.         break
  31.  
  32.     command = input()
  33.  
  34. if len(numbers) > 0:
  35.     print("Sorry you lose :(")
  36.     for i in numbers:
  37.         print(i, end=" ")
  38. else:
  39.     print(f"You have won in {turns} turns!")
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement