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')

24th Feb 2021, 3:24 AM
Carl Aas
6 Réponses
+ 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
24th Feb 2021, 4:24 AM
noteve
noteve - avatar
+ 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.
24th Feb 2021, 3:24 AM
Carl Aas
+ 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')
26th Feb 2021, 12:45 AM
Hasan Hüseyin Semiz
Hasan Hüseyin Semiz - avatar
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
24th Feb 2021, 3:29 AM
Michal Doruch
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.
24th Feb 2021, 4:11 AM
Carl Aas
- 1
Then it should be if 75.0 <= purity <= 83.3 etc.
24th Feb 2021, 4:29 AM
Michal Doruch