Build a Discount Calculator - Build a Discount Calculator

Tell us what’s happening:

I can’t pass tests 3-6, I left my if and first elif statements different to show some of the things I’ve tried for tests 3 and 4 since they are basically the same if I’m understanding the problem correctly. Tests 5 and 6 seem to work if I enter values outside of the set out ranges. I’ve spent maybe 3 hours on rereading the course/google/YouTube and I’m at a loss. Is there links to better explanations of how functions and scopes work? Just seems like I’m asking for help to get through every test

Your code so far

def apply_discount (price, discount):

    if not isinstance(price,(int,float)):
        print('The price should be a number')
    elif isinstance(discount,str):
        print('The discount should be a number')
    elif 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')
    else:
        apply_discount = price - price * discount / 100
        print(apply_discount)
    return(apply_discount)
    
apply_discount(100,20)
apply_discount(200,50)
apply_discount(50,0)
apply_discount(1,100)
apply_discount(74.5,20)




Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0

Challenge Information:

Build a Discount Calculator - Build a Discount Calculator

Only few honest mistakes here:

  1. You’re asked to return and not print.
  2. These two are not the same:
not isinstance(var, (float, int)) != isinstance(var, str)

Fixing these will pass you the lab.

Clearly, I’m new to this so maybe you can explain it to me. My understanding is that it only recognizes strings, integers and floats. So, if I say check that it’s not a int, now check that it’s not float and so if it’s not either would that not imply that is has to be a string?

no, it doesn’t, there are more data types than float, int and str, you will meet them going forward, and there are more that you will not meet in the curriculum

example: try print(type(apply_discount))

1 Like

wow that lesson was a struggle, thank you very much for your help!