Advertisement
go6odn28

Python-Basics Nested Loops - Lab_4_sum_of_2_numbers

Oct 8th, 2023
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. starting_interval = int(input())
  2. final_interval = int(input())
  3. magic_number = int(input())
  4.  
  5. combination_counter = 0
  6. magic_number_condition = False
  7. print_data = ''
  8.  
  9.  
  10. for x in range(starting_interval, final_interval + 1):
  11.     for y in range(starting_interval, final_interval + 1):
  12.  
  13.         combination_counter += 1
  14.  
  15.         if x + y == magic_number:
  16.             magic_number_condition = True
  17.             print_data = f'Combination N:{combination_counter} ({x} + {y} = {magic_number})'
  18.             break
  19.  
  20.     if magic_number_condition:
  21.         break
  22.  
  23. if magic_number_condition:
  24.     print(print_data)
  25. else:
  26.     print(f"{combination_counter} combinations - neither equals {magic_number}")
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement