def apply_discount(price,discount):
#Conditional to check if the price is a number
if isinstance(price,int) or isinstance(price,float):
is_price_number = True
#Nested Conditional to check if the discount is a number
if isinstance(discount,int) or isinstance(discount,float):
is_discount_number = True
else:
is_discount_number = False
print("The discount should be a number")
else:
is_price_number = False
print("The price should be a number")
#Conditional to Check Realistic Price
if is_price_number:
if price <= 0:
is_price_real = False
print("The price should be greater than 0")
else:
is_price_real = True
#Conditional to Check Realistic Discount
if is_discount_number:
if discount <= 0 or discount > 100:
is_discount_real = False
print("The discount should be between 0 and 100")
else:
is_discount_real = True
#Checks if discount and price is a number is true
if (is_discount_number and is_price_number):
#Check if is discount and price is reasonable
if is_discount_real and is_price_real:
price = price-(price * discount/100)
else:
pass
else:
print("Function failed")
return price
apply_discount(30,40)
Got the code working before but I accidentally exited the tab. I’ve tried using Ai to help me understand reasons why I am failing, but it seems to be rewriting my code instead of helping me understand why my bad code isn’t working.