Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Задача 5
- # Напишете функция, която връща произведението на числата в зададения диапазон.
- # Границите на диапазона се подават като параметри.
- # Ако границите на диапазона са объркани (например 5 е горната граница, а 25 е долната граница),
- # разменете ги.
- def faktoriel_in_range (lower, upper):
- lower_bound = min(int(lower), int(upper))
- upper_bound = max(int(lower), int(upper))
- num_range = 1
- for i in range(lower_bound, upper_bound + 1):
- num_range *= i
- return num_range
- num_lower = input("Please enter a integer: ")
- num_upper = input("Please enter a integer: ")
- while True:
- if num_lower.isdigit() and num_upper.isdigit():
- print(f"Тhe multiplication of the numbers from {num_lower} to the {num_upper} is: {faktoriel_in_range(num_lower, num_upper)}")
- break
- elif not num_lower.isdigit():
- num_lower = input("You must enter an integer for the first value!: ")
- elif not num_upper.isdigit():
- num_upper = input("You must enter an integer for the second value!: ")
Advertisement
Add Comment
Please, Sign In to add comment