Tell us what’s happening:
My code works fine in the terminal, but it doesnt pass the test.
def apply_discount(price, discount):
return price - (price * discount / 100)
try:
price = float(input())
except ValueError:
print(“The price should be a number”)
exit()
try:
discount = float(input())
except ValueError:
print(“The discount should be a number”)
exit()
if price <= 0:
print(“The price should be greater than 0”)
elif…
else:
result = apply_discount(price, discount)
print(result)
Your code so far
def apply_discount(price, discount):
return price - (price * discount / 100)
try:
price = float(input())
except ValueError:
print("The price should be a number")
exit()
try:
discount = float(input())
except ValueError:
print("The discount should be a number")
exit()
if price <= 0:
print("The price should be greater than 0")
elif discount < 0 or discount > 100:
print("The discount should be between 0 and 100")
elif discount == 100:
print(0)
else:
result = apply_discount(price, discount)
print(result)
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36
Challenge Information:
Build an Apply Discount Function - Build an Apply Discount Function