0

# Help on code about purity check

purity = float(input()) if purity >= 75.0 <= 83.3: print ('18K') elif purity >= 83.4 <= 91.7: print ('20K') elif purity >= 91.8 <= 99.8: print ('22K')

2/24/2021 3:24:33 AM

Carl Aas

+3

Carl Aas It seems like the values in your condition are different. For example 83.3% should belong to 20K and not 18K. Another possible error is that you are missing a condition for 24K. TO SOLVE: - Adjust values and conditions and add else at the end for 24K. https://code.sololearn.com/cigg4M7F9fJ3/?ref=app

+1

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.

+1

Carl Aas The code should be like this😊 purity = float(input()) if 75.0 <= purity < 83.3: print ('18K') elif 83.3 <= purity < 91.7: print ('20K') elif 91.7 <= purity < 99.9: print ('22K') else: print ('24K')

0

So what is the problem? The only thing that I see is this quotation mark. Shouldn't you use double quotation marks if writing string? As far as I know, python is based on C language, where we use "string" (double quotation marks) to output strings and 'c' (single quotation marks) to output single characters

0

I think in Python you can use both single and double quotation marks. I don't think It should matter. That is at least how I understood it.

-1

Then it should be if 75.0 <= purity <= 83.3 etc.