0

Python for Beginners Boolean Logic 24k Magic

I can't solve Hidden Test Case 7, this ist my Code: 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.99): print ("22K") elif (purity >= 99.99): print ("24K") Thank's for Help.

21st Feb 2022, 4:43 PM
Jens Kopsch
Jens Kopsch - avatar
7 Respostas
+ 2
99.9
21st Feb 2022, 4:44 PM
Simba
Simba - avatar
+ 2
You have two 99.99 values in conditions.
21st Feb 2022, 4:59 PM
Simba
Simba - avatar
+ 1
# You can compare with this one: 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") elif 99.9 <= purity <= 100.0: print("24K")
21st Feb 2022, 5:29 PM
Per Bratthammar
Per Bratthammar - avatar
0
Hi! Do you know you can write a >= b and a < c as b <= a < c ? What happend ’else’ ?
21st Feb 2022, 4:50 PM
Per Bratthammar
Per Bratthammar - avatar
0
I know this, but is more easy to read for me. I changed the 99.99 to 99.9 but the Test Case 7 is anymore red 😔
21st Feb 2022, 4:54 PM
Jens Kopsch
Jens Kopsch - avatar
0
Thank you, your Code is working well. 😀
21st Feb 2022, 8:00 PM
Jens Kopsch
Jens Kopsch - avatar
0
This quiz is wrong. Your code is correct, but the SoloLearn test 7 will flag it as incorrect, look at what I changed on my last statement that gave me a green pass: purity = float(input()) if purity >= 75 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") else: print("24K") .... How does an else statement at the end make any sense? I input "55" and the result was "24K" yet I passed....
17th Sep 2022, 1:08 AM
Adam Knight