Build an Apply Discount Function - Build an Apply Discount Function

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

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-discount-calculator/695774002591bbc5f8cf3e53.md at main · freeCodeCamp/freeCodeCamp · GitHub

Welcome to the forum @freecode_user79,

Your function is returning immediately without validating price and discount.

All of the code past the first line is not inside the function.

You are printing where the instructions ask you to return.

Here you are calling the function recursively rather than returning the final price (like you did in your first line of code).

You have some work to do, so I suggest reviewing the user stories to make sure you are implementing them correctly and using the methods you have been taught; for example, do you know what the input() and exit() methods are doing and are they appropriate for this challenge?

Happy coding