sibinasto

11.04. Sum of two number

Dec 5th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. start = int(input())
  2. end = int(input())
  3. magic_number = int(input())
  4. combinations = 0
  5. magic_number_found = False
  6.  
  7. for x in range(start, end+1):
  8.     for y in range(start, end+1):
  9.         combinations += 1
  10.         sum = x + y
  11.         if sum == magic_number:
  12.             print(f'Combination N:{combinations} ({x} + {y} = {magic_number})')
  13.             magic_number_found = True
  14.             break
  15.         if magic_number_found:
  16.             break
  17.  
  18. if not magic_number_found:
  19.     print(f'{combinations} combinations - neither equals {magic_number}')
Advertisement
Add Comment
Please, Sign In to add comment