Advertisement
Spocoman

09. Sum of Two Numbers

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