# Boolean Logic Question

I am getting 6 out of 7 tests right but I cant see the final hidden test, what am I missing here? purity = float(input()) if (purity == 99.99): print("24K") else: if(purity <= 99.98 and purity >= 91.70): print("22K") else: if(purity <= 91.69 and purity >= 83.30): print("20K") else: if(purity <= 83.29 and purity >= 75.00): print("18K") else: if(purity < 74.99): print()

10/27/2021 4:00:48 AM

Sam Waters7 Answers

New AnswerYou're leaving huge gaps beetwen an if and the next (e.g.: from 99.98 and 99.99). You can just get rid of them (purity<=99.98 etc.), as they're already handled by 'else' Also, it's better to avoid checking for float equivalence P.S.: there is a wonderful keyword called 'elif', try it

Sam Waters Try replacing “print()”in the last line with “pass”, so it won't output anything and you won't get EOF error

I tried elif and it gave me an error, I still need to understand that a little more how to finish the line with elif I think. I changed my formula to; if(purity < 99.99 and purity >= 91.70): print("22K") that should eliminate any gap between the 24k at 99.99 and the 22k which is less then 99.99 but not equal to it. I added pass and it did not solve test 7 (hidden still). here is the question I am stuck on; Now that we know how to combine multiple conditions, let’s improve our gold purity checker program and output the corresponding purity level in Karats! Here is the purity chart we’ll be using: 24K – 99.9% 22K – 91.7% 20K – 83.3% 18K – 75.0% If the percentage is between 75 and 83.3, the gold is considered to be 18K. If it's between 83.3 and 91.7, then it’s 20K, and so on. Given the percentage as input, output the corresponding Karat value, including the letter K. Sample Input: 92.4 Sample Output: 22K Do not output anything if the percentage is lower than 75%.