Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions 7_exception2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,36 @@
* Первые два нужно приводить к вещественному числу при помощи float(),
а третий - к целому при помощи int() и перехватывать исключения
ValueError и TypeError, если приведение типов не сработало.

"""

def discounted(price, discount, max_discount=20)
"""
Замените pass на ваш код
"""
pass

def discounted(price, discount, max_discount=-23.4):

try:
price = abs(float(price))
discount = abs(float(discount))
max_discount = abs(int(max_discount))
except(ValueError):
raise ValueError("неправильно!")
except(TypeError):
raise ValueError("неправильный тип переменной!")

if max_discount >= 100:
raise ValueError('Максимальная скидка не должна быть больше 100')

print(f'{max_discount=} {discount=}')
if discount >= max_discount:
price_with_discount = price
else:
price_with_discount = price - (price * discount / 100)

return price_with_discount


if __name__ == "__main__":
print(discounted(100, 2))
print(discounted(100, "3"))
print(discounted("100", "4.5"))
print(discounted("five", 5))
# print(discounted(100, 2, 105))
# print(discounted(100, "3"))
# print(discounted("100", "4.5"))
# print(discounted("five", 5))
print(discounted("сто", "десять"))
print(discounted(100.0, 5, "10"))
# print(discounted(100.0, 5, "10"))