+ 1

Python 24K Magic

Hi, I am new to coding... I don't understand how I get Python to not output anything if the value is lower than 75%. Here's my code: purity = float(input()) if (purity >= 99.9): print ("24K") elif (purity <= 91.70 and purity >= 99.8): print ("22K") elif (purity >= 83.3 and purity <= 91.6): print ("20K") elif (purity >= 75.0 and purity <= 83.2): print ("18K") Can someone help? It fails two of the 7 test cases... I suspect with numbers below 75.0

25th Nov 2021, 12:21 AM
Sarah Aardwolf
3 Respostas
+ 3
purity = float(input()) if purity >= 99.9 : print ("24K") elif purity >= 91.7 : print ("22K") elif purity >= 83.3 : print ("20K") elif purity >= 75 : print ("18K") else: print ("?K", purity) # Unknown https://code.sololearn.com/cVBb1Wfxn484
25th Nov 2021, 12:46 AM
SoloProg
SoloProg - avatar
+ 1
It would not hurt to find out the assignment.
25th Nov 2021, 12:28 AM
Solo
Solo - avatar
+ 1
Take another look at your condition for 22K. It's impossible to fulfill it. Also, notice that there are gaps between your categories.
25th Nov 2021, 12:45 AM
Simon Sauter
Simon Sauter - avatar