Похожие чаты

Can you rate this code? How readable is it? And

how 'pythonic' is it?

9 ответов

14 просмотров

My old teacher would've pressed ENTER once and fail you for it.

Tushar- Автор вопроса
Tushar
How should I handle it?

Verify that input is actually valid before continuing.

Tushar- Автор вопроса
Martin Rys
Verify that input is actually valid before continu...

# 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))

Tushar
# Write a program that takes a number from user an...

you should avoid recursion in this case, use a loop

Tushar
# Write a program that takes a number from user an...

also the odd_numbers is a waste of resources, use the third argument for range

Tushar- Автор вопроса
Tushar
I didn't get you?

what's not clear?

Tushar- Автор вопроса
Muflone
what's not clear?

https://termbin.com/wnji

Похожие вопросы

Обсуждают сегодня

Hi everyone! I have a two-folded message to share today. First: updates and news, as we are being asked for those. We still want to go like we did the last 6 years: we w...
Marten | Unibright.io
31
Интересно, нет ли какого-то способа получить из dll не адрес самой метки, а адрес со смещением?
The Bird of Hermes
54
generic procedure function test<T>(param: T); type case T of longint: NewT = word; longword: NewT = byte; end; var v1: NewT; Как это можно сделать? Чтобы у меня...
notme
21
Guys, mexc or gate.io (only exchanges with the token I need, unfortunately): depositing xmr, not withdrawing, is safe rn, or can fall for shotgun kyc? (I heard gate is alread...
another one bites the dust
20
Whoa, did you guys see this FUNToken Seed Grant announcement? 💸
Noah Noure
37
Делал задачу вот такую https://stepik.org/lesson/4985/step/9?unit=1083 получилось такое https://play.haskell.org/saved/ipKrepqe оно работает, тестов много не писал, но работае...
Fedor
22
hello guys, I have a laptop, if you connect wired headphones, the sound will come from the headphones and the built-in speakers AT THE SAME TIME. How can I make the sound com...
El Pepe
21
Ok, now that the formal part is done, we can talk funny stuff. What is the next big thing ( in crypto/blockchain) we should look into? What are your favorite series on Netflix...
Marten | Unibright.io
11
Всем добрый вечер. Нужна помощь с прикруткой telegram-vapor-bot к проекту Vapor. Удалось после старта приложения отправить тестовое сообщение в бот, вот только сразу после это...
advanc3d
3
program Project1; procedure generic_proc<T>(); begin end; begin generic_proc<Int64>(0); end. Я чет не понял, а как в Delphi сделать такое? процедуру-дженерик... PS: а на...
notme
10
Карта сайта