My old teacher would've pressed ENTER once and fail you for it.
How should I handle it?
Verify that input is actually valid before continuing.
# Write a program that takes a number from user and find 3 odd numbers # from 1 to 15 whose sum is equal to the entered number otherwise tell # the user "impossible" import string def find_odd_pair(number: int): odd_numbers: list[int] = [n for n in range(1, 15 + 1) if n % 2 != 0] for i in odd_numbers: for j in odd_numbers: if i != j: k: int = number - j - i if k in odd_numbers and k not in (j, i): return i, j, k return "impossible" def get_number(message: str = ""): raw_input: str = input(message) try: return int(raw_input) except ValueError: return get_number(message) number: int = get_number("Enter the number: ") print(find_odd_pair(number))
you should avoid recursion in this case, use a loop
also the odd_numbers is a waste of resources, use the third argument for range
I didn't get you?
what's not clear?
https://termbin.com/wnji
Обсуждают сегодня