Need help with the gold purity Boolean logic problem | Sololearn: Learn to code for FREE!

+1

Need help with the gold purity Boolean logic problem

I'm running this code and it's showing errors on test 5 purity = float(input()) if purity >= 75.0 and purity < 83.3: print ("18K") if purity >= 83.3 and purity < 91.7: print ("20K") if purity >= 91.7 and purity < 99.9: print ("22K") if purity >= 99: print ("24K") Any help would be appreciated 🙂

8/6/2021 1:18:05 PM

Tophyy

6 Answers

New Answer

+5

Try: purity = float(input()) if purity >= 75.0 and purity < 83.3: print ("18K") elif purity >= 83.3 and purity < 91.7: print ("20K") elif purity >= 91.7 and purity < 99.9: print ("22K") elif purity >= 99.9: print ("24K")

+1

Could you post the task here?

+1

Thank you that worked. What was I doing wrong then 😅

+1

1. use elif so statements are only considered if original if is not the case. 2. You wrote >= 99 instead of 99.9 in the last statement

+1

Oh thank you I didn't see the 99.9 part and I'll remember to use elif also thanks.

0

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