I just need assistance with steps 7 and 8. I am pretty stuck, and
def apply_discount (price, discount):
if not isinstance (price, (int or float)):
return ('The price should be a number')
elif not isinstance(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')
Hmmm!!
I think I am overthinking
Your code so far
def apply_discount (price, discount):
if not isinstance (price, (int or float)):
return ('The price should be a number')
elif not isinstance(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')
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Challenge Information:
Build an Apply Discount Function - Build an Apply Discount Function
The print call will print the result of calling your function.
The return keyword is used inside a function. For debugging, placing the function call inside a print call prints the result to the console, so the return keyword is not used.
Make sure the print call is not indented. It should not appear in the body of the function.
hmm I’m still confused I guess on what I am missing in understanding this hint??
def apply_discount (price, discount):
if not isinstance (price, (int or float)):
return ('The price should be a number')
elif not isinstance(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')
and when applying
print(apply_discount(100, 20))
it prints out “none” on the terminal.
I guess my question is what is this supposed to show or help me understand. I am most likely overthinking this.
Well no that wouldn’t be valid since I’m not trying to print the discount, I am trying to print the final_price…. Oh, so would it be
print (final_price)
so my code wou be this
def apply_discount (price, discount):
if not isinstance (price,(int or float)):
return ('The price should be a number')
elif not isinstance(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')
else:
discount= price * (discount/100)
final_price= price - discount
print (final_price)
It is great that you solved the challenge, but 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
Please create your own topic when you have specific questions about your own challenge code. Only respond to another thread when you want to provide help to the original poster of the other thread or have follow up questions concerning other replies given to the original poster.
The easiest way to create a topic for help with your own solution is to click the Help button located on each challenge. This will automatically import your code in a readable format and pull in the challenge URL while still allowing you to ask any question about the challenge or your code.