Advertisement
nikol_bratkova

Untitled

Apr 28th, 2022
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. ############################################################################
  2.  
  3. # gets the target sum
  4. target = int(input())
  5.  
  6. # gets the numbers
  7. input_list = input().split()
  8.  
  9. # stores numbers <= target sum in list <numbers>
  10. numbers = []
  11. for element in input_list:
  12. if int(element) <= target:
  13. numbers.append(int(element))
  14.  
  15. for i in range(len(numbers)): # range(len(numbers) - indeces of items in the list <numbers>
  16. x = target - numbers[i] # sum of which number <x> and i element of numbers, for short the number, gives <target>
  17. right_numbers = numbers[i+1:] # list with numbers at right of the number in the list <numbers>
  18.  
  19. if x in right_numbers: # if searched number <x> is at right
  20. seen_times = right_numbers.count(x) # how many times <x> is there?
  21. for times in range(seen_times): # each time
  22. print(f'{numbers[i]}, {x}') # print the number and <x>
  23.  
  24. ############################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement