+ 1
My code fails at the last test case... can't find what's wrong. Appreciate your help on this one.
13 Respostas
+ 2
Last try. Could you please copy and try this one?
https://code.sololearn.com/cKP5ivhj2oWP/?ref=app
+ 2
24K is considered 99.9 and above.
Changing the last condition to >= 99.9 might solve it.
Edit. The Limit for 24K is 99.9%, not 99.99% btw...
+ 1
Sometimes the hidden test cases include values that donât fit your assumed ranges. Such as, if purity is <75 or ==100. Do the instructions tell you what to print if the purity is not within range?
+ 1
Try
if purity>=99.9:
print ("24K")
Instead of
if purity==99.99:
print ("24K")
Greater than, not equal
99.9% not 99.99%
But I can't test it.
+ 1
Or maybe the first case from
>= 99.9
to only
>99.9
But that's it. And Idk.
+ 1
CĂąndido Abreu, have you chnged 99.99 in both if cases (the last one AND the one before) ?
If not, you might have got both if cases true, which could cause another test to fail.
When you tried the >= Version, was it with 99.99 or 99.9%?
And Yes it is true, 100% Gold does not exist, But 99.999 is still great er than 99.99. And 99.9999 is even greater. And there are a whole lot more examples :)
Coding Cat [Mouse searching] your attempt should be working, I think:)
+ 1
Thank you all!
Coding Cat [Mouse searching] your code works đđ»
It's more simple than mine I think.
+ 1
Its not a syntax error just logic error Try this
# Created by CĂąndido Abreu
purity = float(input())
if purity > 99.9:
print("24K")
elif purity > 91.7:
print("22K")
elif purity > 83.3:
print("20K")
elif purity > 75.0:
print("18K")
0
Jerry
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
Below 75 don't output anything
0
Changing from 99.99 to 99.9 fails in 2 test cases instead of 1.
Regarding changing == for >= I already tried with no effect. In the introduction to the test is referred that 100% pure gold doesn't exist.