Skip to content

Conversation

@Shestakas
Copy link

ДЗ 1

Copy link

@krepysh krepysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это явно зачет, просто пара моментов где можно чуть срезать углы в коде. Желательно пофиксить.

"""
def prof_by_age(age):
if age <= 6:
return 'учиться в детском саду'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это такой пограничный случай. Если бы веток было бы больше, я бы однозначно рекомендовал использовать один return на функцию.
Есть два метода этого достичь:

  1. Либо в функции объявляешь переменную rv (сокращенно от return_value) и присваиваешь ей значение в ветках, а в конце просто return rv.
  2. Либо можно использовать табличную функцию: положить возвращаемые значения в словарь и по ключу доставать. Но тут сложно будет с ключом рабоатать, лучше первый вариант взять.

pass
while True:
try:
age = int(input('----Для выхода введите 0 ----\nВведите ваш возраст: '))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здорово что прикрутил обработку исключений, но в таком случае внутри try блока надо оставить только ту строчку в которой у тебя это исключение может возникнуть. (age = int(input()).
Остальное вынести после except.

return 3
elif len(one) > len(two):
return 2
else:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else: pass не несет никакого смысла тут, можно убрать и код не изменится (только станет проще)

whatsup = input('Как дела?:')
if whatsup.lower() == 'хорошо':
break
else:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь тоже блок else никак не влияет на выполнение кода


questions_and_answers = {}
def external_ip():
external_ip = str(urllib.request.urlopen('https://ident.me').read().decode('utf8')) #Обработать try/except
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сложный путь сделать запрос 🙂
import requests
requests.get('https://ident.me').text

return external_ip
ext_ip = external_ip()
questions_and_answers = {"Как дела?": "Хорошо!", "Что делаешь?": "Программирую", "Какой у тебя ip?": f'{ext_ip}'}
quest = ''.join(f'{k}'+',' for k in questions_and_answers.keys())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если используешь f-строку то и запятую сразу в нее перенести стоит.
А вообще тут даже так можно:
','.join(questions_and_answers.keys())

max_discount_int = int(max_discount)
return (price_float, discount_float, max_discount_int)
except TypeError:
return ('TypeError')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Скобки лишние, это просто строка. (Если хочешь тупл из одного элемента, надо запятую добавить перед закрывающей скобкой)

dt_now = date.today()
b = update.message.text #(update['message'])['text']
d = ((b.split())[1]).lower()
if d == 'mars':
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы предложил это все сложить в словарь и вытаскивать из словаря. Тогда когда откроют новую планету не придется менять логику кода, а просто добавить еще один объект в словарь.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants