Advertisement
Spocoman

04. Sum of Two Numbers

Dec 30th, 2021 (edited)
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. start = int(input())
  2. end = int(input())
  3. magic =int(input())
  4. combinations = 0
  5. is_magic = False
  6.  
  7. for i in range(start, end + 1):
  8.     for j in range(start, end + 1):
  9.         combinations += 1
  10.         if i + j == magic:
  11.             print(f"Combination N:{combinations} ({i} + {j} = {magic})")
  12.             is_magic = True
  13.             break
  14.     if is_magic:
  15.         break
  16.        
  17. if not is_magic:
  18.     print(f"{combinations} combinations - neither equals {magic}")
  19.  
  20. Или:
  21.  
  22. start = int(input())
  23. end = int(input())
  24. magic = int(input())
  25. combinations = 0
  26.  
  27. for i in range(start, end + 1):
  28.     for j in range(start, end + 1):
  29.         combinations += 1
  30.         if i + j == magic:
  31.             print(f"Combination N:{combinations} ({i} + {j} = {magic})")
  32.             exit(0)
  33.  
  34. print(f"{combinations} combinations - neither equals {magic}")
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement