My program is unable to complete the 5th and 6th objective. I have switched the print statements to return and the final price doesn’t return which is really frustrating. How can I fix this?
Your code so far
def apply_discount(price, discount):
priceClass = isinstance(price, (int,float))
if priceClass != True:
return("The price should be a number")
discountClass = isinstance(discount, (int, float))
if discountClass != True:
return ("The discount should be a number")
# Calculation
discountedPrice = discount * price/100
finalPrice = (price - discountedPrice)
if price <= 0:
print("The price should be greater than 0")
if discount <= 0 or discount > 100:
print("The discount should be between 0 and 100")
return finalPrice
print(apply_discount(50,0))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0
Challenge Information:
Build a Discount Calculator - Build a Discount Calculator
I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add the backticks.
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
if price <= 0:
return "The price should be greater than 0"
if discount <= 0 or discount > 100:
return "The discount should be between 0 and 100"
return finalPrice
print(apply_discount(50,0))
It doesn’t return anything in the console. I don’t know why.
I edited this. I realized the last print was indented in the function. this is the new code
if price <= 0:
return "The price should be greater than 0"
if discount <= 0 or discount > 100:
return "The discount should be between 0 and 100"
return finalPrice
print(apply_discount(50,0))
It doesn’t print the final price which I need to complete the 8th objective. How can I fix this?