Tell us what’s happening: i write the code, that i believe should be correct, but it doesnt work. the price one where if the price isnt a number it returns a string is correct , but the one with discount which is almost identical is somehow wrong . Dont pay attention to the user stories 7 and 8 of this , i diditn write themm yet
Your code so far
def apply_discount(price, discount):
if price != (int or float):
return 'The price should be a number'
elif discount != (int or float):
return 'The discount should be a number'
elif price <= 0:
return 'The price should be greater than 0'
elif discount < 0 or discount > 100:
return 'The discount should be between 0 and 100'
Please review this theory lecture about how to check the type of a variable, especially the last example, which shows how to check a variable against more than one type:
i still dont get it, as even when i try to check what type of variable the price or discount is it says that they are not defined, so i cant do anything…
def apply_discount(price, discount):
if isinstance(price, (int, float)) == False:
return 'The price should be a number'
elif isinstance(discount, (int, float)) == False:
return 'The discount should be a number'
elif price <=0:
return 'The price should be greater than 0'
elif discount < 0 or discount >100:
return 'The discount should be between 0 and 100'
apply_discount(100,20)
print(apply_discount(100,20))
def apply_discount(price, discount):
if isinstance(price, (int, float)) == False:
return 'The price should be a number'
elif isinstance(discount, (int, float)) == False:
return 'The discount should be a number'
elif price <=0:
return 'The price should be greater than 0'
elif discount < 0 or discount >100:
return 'The discount should be between 0 and 100'
elif isinstance(price and discount, (int, float))==True:
return price - discount
apply_discount(100,20)
print(apply_discount(100,20))
you do not need an additional condition here, but I would double check how to calculate the discount, remember that the discount is a percentage, not a discount in dollars