24 k magic problem (module 4 python for beginners) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

24 k magic problem (module 4 python for beginners)

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 Here the code I have done purity = float(input()) if purity >= 99.99 and purity <= 100: print("24K") elif purity >= 91.7: print("22K") elif purity >= 83.3: print("20K") elif purity >= 75.0: print("18K") This code pass all test case except the last test case (test case 7) Please help me ...finding which part I done wrong

28th Feb 2021, 1:08 PM
Abhishek Biswas
Abhishek Biswas - avatar
14 Answers
+ 10
@Simba thanks for suggestion ..it worked!!
28th Feb 2021, 1:24 PM
Abhishek Biswas
Abhishek Biswas - avatar
+ 4
p = float(input()) if p >= 75.0 and p < 83.3: print('18'+'K') elif p >= 83.3 and p < 91.7: print('20'+'K') elif p >= 91.7 and p < 99.9: print('22'+'K') elif p >= 99.9: print('24'+'K')
28th Apr 2021, 11:33 PM
Денис Матвеев
Денис Матвеев - avatar
+ 3
purity = float(input()) if purity > 99.9: print("24K") elif purity > 91.7 and purity < 99.9: print("22K") elif purity > 83.3 and purity < 91.7: print("20K") elif purity > 75.0 and purity < 83.3: print("18K") else: None
20th May 2021, 6:56 AM
Janhvi Tiwari
Janhvi Tiwari - avatar
+ 2
Please copy and paste the question of the exercise here as some of us are not pro users
28th Feb 2021, 1:14 PM
∆BH∆Y
∆BH∆Y - avatar
+ 2
Okk i am add that in question
28th Feb 2021, 1:16 PM
Abhishek Biswas
Abhishek Biswas - avatar
+ 2
It's 99.9 not 99.99
28th Feb 2021, 1:20 PM
Simba
Simba - avatar
+ 2
Justin cross the problem with your code ,you use 22k with a small letter k instead of using capital K to run it all 7 steps
21st Mar 2022, 6:24 PM
FESTUS KIPROTICH NGENO
FESTUS KIPROTICH NGENO - avatar
+ 1
purity = float(input()) #your code goes here 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.9: print("22k") elif purity>=99.9 and purity<=100: print("24K") else: print("") this code pass all test case excpet case 5 and 6 please tell where is problem
16th Jan 2022, 7:28 PM
BY Tech
BY Tech - avatar
+ 1
Hey i have a simple code: purity = float(input("Enter the gold purity percentage: ")) if purity >= 99.9: print("24K") elif purity >= 91.7: print("22K") elif purity >= 83.3: print("20K") elif purity >= 75.0: print("18K") else: print("Not Accepted")
7th Feb 2023, 3:43 AM
GUNTUR MELLINIAWAN
GUNTUR MELLINIAWAN - avatar
0
Ok so I ran this exact code about 20 times. Logged out and back in, left for the night and tried the next day, looked in this blog and checked the solution (this is the same as the solution) and after all that, logged out and closed the app it finally gave me the points and said my code was correct. purity = float(input()) #your code goes here if purity >= 75 and purity < 83.3: print("18K") if purity >= 83.3 and purity < 91.7: print("20K") if purity >= 91.7 and purity < 99.9: print("22k") if purity > 99.9: print("24K")
8th Mar 2022, 3:35 AM
justin cross
0
purity = float(input()) #your code goes here if purity >= 99.99 and purity <=100: print("24K") elif purity >= 91.7 and purity <=99.9: print("22K") elif purity >= 83.3 and purity <=91.7: print("20K") elif purity >= 75.0 and purity <=83.3: print("18K") else: print("")
3rd Jul 2022, 11:09 AM
Mohammad Zaid
Mohammad Zaid - avatar
0
purity = float(input()) if purity >= 99.9 and purity <= 100: print("24K") elif purity >= 91.7 and purity <99.9: print("22K") elif purity >= 83.3 and purity < 91.7: print("20K") elif purity >= 75.0 and purity < 83.3: print("18K") else: print("")
2nd Oct 2022, 10:49 AM
Abdelrahman Mahmoud Hamed
0
purity = float(input()) #your code goes here if purity>99.9: print("24K") elif purity>91.7: print("22K") elif purity>=83.3: print("20K") elif purity>=75.0: print("18K") else: print("Invalid")
21st Mar 2023, 3:50 AM
Vithushan Vinayakamoorthy
- 1
Thank me later 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") if purity > 99.9: print("24K")
9th Oct 2022, 4:52 AM
Nasratullah
Nasratullah  - avatar