zyulfi

Мultiplication_of_numbers

Jun 4th, 2025 (edited)
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | Source Code | 0 0
  1. # Задача 5
  2. # Напишете функция, която връща произведението на числата в зададения диапазон.
  3. # Границите на диапазона се подават като параметри.
  4. # Ако границите на диапазона са объркани (например 5 е горната граница, а 25 е долната граница),
  5. # разменете ги.
  6.  
  7. def faktoriel_in_range (lower, upper):
  8.     lower_bound = min(int(lower), int(upper))
  9.     upper_bound = max(int(lower), int(upper))
  10.     num_range = 1
  11.     for i in range(lower_bound, upper_bound + 1):
  12.         num_range *= i
  13.     return num_range
  14.  
  15. num_lower = input("Please enter a integer: ")
  16. num_upper = input("Please enter a integer: ")
  17.  
  18. while True:
  19.     if num_lower.isdigit() and num_upper.isdigit():
  20.         print(f"Тhe multiplication of the numbers from {num_lower} to the {num_upper} is: {faktoriel_in_range(num_lower, num_upper)}")
  21.         break
  22.     elif not num_lower.isdigit():
  23.         num_lower = input("You must enter an integer for the first value!: ")
  24.     elif not num_upper.isdigit():
  25.         num_upper = input("You must enter an integer for the second value!: ")
  26.  
Advertisement
Add Comment
Please, Sign In to add comment