SHARE
TWEET

04. Sum of Two Numbers

a guest Dec 8th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. start_number = int(input())
  2. end_number = int(input())
  3. magic_number = int(input())
  4. count_combinations = 0
  5. is_found_valid_combination = False
  6. for first_number in range(start_number, end_number + 1):
  7.     if is_found_valid_combination:
  8.         break
  9.     for second_number in range(start_number, end_number + 1):
  10.         count_combinations += 1
  11.         #valid -> first_number + second_number = magic_number
  12.         if first_number + second_number == magic_number:
  13.             print(f'Combination N:{count_combinations} ({first_number} + {second_number} = {magic_number})')
  14.             is_found_valid_combination = True
  15.             break
  16. if not is_found_valid_combination:
  17.     print(f"{count_combinations} combinations - neither equals {magic_number}")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top