Conte-nos o que está acontecendo:
Quando apply_discount é chamado com um price (primeiro argumento) que não é um número (int ou float) ele deve retornar The price should be a number.
Seu código até o momento
def verificar_preco(x):
if type(x) is bool or type(x) is str:
return "The price should be a number."
if x < 0:
return "The price should be greater than 0."
return True
def verificar_desconto(y):
if type(y) is bool or type(y) is str:
return "The discount should be a number."
if y < 0 or y > 100:
return "The discount should be between 0 and 100."
return True
def apply_discount(price, discount):
ver1 = verificar_preco(price)
ver2 = verificar_desconto(discount)
if ver1 is True and ver2 is True:
x = (discount * price) / 100
final = price - x
print(f"Success! Final price: {final}")
return final
else:
if type(ver1) is str:
print(f"Error (Price): {ver1}")
if type(ver2) is str:
print(f"Error (Discount): {ver2}")
print("-" * 30)
apply_discount(100, 20)
apply_discount(200, 50)
apply_discount(50, 100)
apply_discount(74.5, 20)
apply_discount(True, 20)
apply_discount(-5, 20)
apply_discount(5, -20)
Informações do seu navegador:
Agente de usuário: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0
Informações do desafio:
Crie uma função para aplicar desconto - Criar uma função Apply Discount