Lyubohd

04. Sum of Two Numbers

Jun 12th, 2021
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. start = int(input())
  2. stop = int(input())
  3. magic_number = int(input())
  4.  
  5. counter = 0
  6. flag = False
  7.  
  8. for i in range(start, stop + 1):
  9.     for j in range(start, stop + 1):
  10.         current_sum = i + j
  11.         counter += 1
  12.         if current_sum == magic_number:
  13.             flag = True
  14.             print(f"Combination N:{counter} ({i} + {j} = {magic_number})")
  15.             break
  16.     if flag:
  17.         break
  18.  
  19. if not flag:
  20.     print(f"{counter} combinations - neither equals {magic_number}")
  21.  
Advertisement
Add Comment
Please, Sign In to add comment