-
Notifications
You must be signed in to change notification settings - Fork 469
for review #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
for review #145
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,12 @@ | |
| Условный оператор: Сравнение строк | ||
|
|
||
| * Написать функцию, которая принимает на вход две строки | ||
| * Проверить, является ли то, что передано функции, строками. | ||
| * Проверить, является ли то, что передано функции, строками. | ||
| Если нет - вернуть 0 | ||
| * Если строки одинаковые, вернуть 1 | ||
| * Если строки разные и первая длиннее, вернуть 2 | ||
| * Если строки разные и вторая строка 'learn', возвращает 3 | ||
| * Вызвать функцию несколько раз, передавая ей разные праметры | ||
| * Вызвать функцию несколько раз, передавая ей разные праметры | ||
| и выводя на экран результаты | ||
|
|
||
| """ | ||
|
|
@@ -20,7 +20,17 @@ def main(): | |
| Эта функция вызывается автоматически при запуске скрипта в консоли | ||
| В ней надо заменить pass на ваш код | ||
| """ | ||
| pass | ||
|
|
||
| string_1, string_2 = input('Введите данные:'), input('Введите данные:') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. функция должна принимать два объекта как аргументы. |
||
| if not string_1.isalpha() and not string_2.isalpha(): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Этот код поломается как только будет передана не строка. |
||
| return 0 | ||
| elif string_1 == string_2: | ||
| return 1 | ||
| elif string_1 == string_2 and len(string_1) > len(string_2): | ||
| return 2 | ||
| elif string_1 != string_2 and string_2 == 'learn': | ||
| return 3 | ||
| else: | ||
| return 'Неизвестные данные' | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,15 +10,40 @@ | |
| * Первые два нужно приводить к вещественному числу при помощи float(), | ||
| а третий - к целому при помощи int() и перехватывать исключения | ||
| ValueError и TypeError, если приведение типов не сработало. | ||
| """ | ||
|
|
||
| def discounted(price, discount, max_discount=20) | ||
| def discounted(price, discount, max_discount=20): | ||
| """ | ||
| Замените pass на ваш код | ||
| """ | ||
| pass | ||
|
|
||
| try: | ||
| price = float(price) | ||
| except (ValueError, TypeError): | ||
| return 'eRRor' | ||
| try: | ||
| discount = float(discount) | ||
| except (ValueError, TypeError): | ||
| return 'eRRor' | ||
| try: | ||
| max_discount = int(max_discount) | ||
| except (ValueError, TypeError): | ||
| return 'eRRor' | ||
| try: | ||
| price = abs(price) | ||
| except: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. обязательно указываем что именно мы хотим перехватить |
||
| discount = abs(discount) | ||
| try: | ||
| max_discount = abs(max_discount) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Слишком длинный блок try, желательно что бы в try была одна строчка. Тут исключение может быть или в abs, или там где мы сами его бросаем. Поменяй raise на return строки просто. |
||
| if max_discount >= 100: | ||
| raise ValueError('Слишком большая максимальная скидка') | ||
| if discount >= max_discount: | ||
| return price | ||
| else: | ||
| return price - (price * discount / 100) | ||
| except (ValueError, TypeError): | ||
| return 'eRRor' | ||
|
|
||
| if __name__ == "__main__": | ||
| print(discounted(100, 2)) | ||
| print(discounted(100, "3")) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вынеси if-ы в отдельную функцию, так что бы она принимала int на вход и ВСЕГДА возвращала строку.