Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ############################################################################
- # gets the target sum
- target = int(input())
- # gets the numbers
- input_list = input().split()
- # stores numbers <= target sum in list <numbers>
- numbers = []
- for element in input_list:
- if int(element) <= target:
- numbers.append(int(element))
- for i in range(len(numbers)): # range(len(numbers) - indeces of items in the list <numbers>
- x = target - numbers[i] # sum of which number <x> and i element of numbers, for short the number, gives <target>
- right_numbers = numbers[i+1:] # list with numbers at right of the number in the list <numbers>
- if x in right_numbers: # if searched number <x> is at right
- seen_times = right_numbers.count(x) # how many times <x> is there?
- for times in range(seen_times): # each time
- print(f'{numbers[i]}, {x}') # print the number and <x>
- ############################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement