Skip to content

Homework_1_Glazunova#173

Open
Olga888-56 wants to merge 9 commits intolearnpythonru:masterfrom
Olga888-56:master
Open

Homework_1_Glazunova#173
Olga888-56 wants to merge 9 commits intolearnpythonru:masterfrom
Olga888-56:master

Conversation

@Olga888-56
Copy link
Copy Markdown

No description provided.

1_if1.py Outdated
def main(age):
if age >= 2 and age < 7:
return "Детский сад"
elif age >= 7 and age < 18:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно ли тут безболезненно заменить

elif age >= 7 and age < 18:

на

elif age < 18:

Почему?

Copy link
Copy Markdown
Author

@Olga888-56 Olga888-56 Dec 1, 2024

Choose a reason for hiding this comment

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

Проверила, можем)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

А если age = 1? :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Здесь затупила. Нет, получается, не можем. Работать будет, но криво. Условия проверяются последовательно. 1>=2 - не верно, поэтому в садик не попадаем, зато однозначно <18, поэтому школа как раз подходит)) исправила, как было.

1_if1.py Outdated

def main():
"""
def main(age):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Давай переназовем функцию для понятности что она делает

age = int(age_in)
activity = main(age)
print(f"Ваше занятие по возрасту {activity}")
input ()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

print(main ("text","123"))
print(main("text","text"))
print(main("texttexttext", "text"))
print(main("text","learn"))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 отлично!

print(f'суммарное количество продаж {all_sales}')
print(f'среднее количество продаж {avg_all_sales}')

main(data)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Супер! Аккуратное выполнение

5_while2.py Outdated
if question in questions_and_answers:
print(answer)
else:
print("я не знаю")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Да, это рабочий вариант. Давай для тренировки избавимся от if-else и попробуем переписать через .get(...)

else:
print('Как дела? ')
except KeyboardInterrupt:
print('Пока!')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

7_exception2.py Outdated
print(discounted(100.0, 5, "10"))
try:
price = abs(price)
price = float(price)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно такие действия объединять
price = float(abs(price))
Или же надо давать разные имена на разных шагах. На самом деле мы стараемся не экономить на именах иначе создается ситуация в которой в разных местах программы под одним именем разные по логике вещи и
raw_price = abs(price)
price = float(raw_price)

7_exception2.py Outdated
else:
price_with_discount = price - (price * discount / 100)
return price_with_discount
except(ValueError, TypeError):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Сейчас у тебя блок except слишком низко.
В итоге сообщение "Максимальная скидка не должна быть больше 100" ты никогда не увидишь так как его сама же перехватишь и заменишь на "Не сработало приведение типов"

Попробуй переместить аккуратно и проверить что приведение типов обрабатывается корректно и max_discount >=100 выдавал свою ошибку

8_ephem_bot.py Outdated
planet_name = planet.split()
print(planet_name)
name = planet_name[1]
Mars = ephem.Mars("2024/11/30")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

А давай заменим "2024/11/30" на переменную отвечающую за текущую дату

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.

2 participants