+ 1

I can't find any error in this. But I am stuck at this level(python for beginners 24.2)

purity = float(input()) 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")

11th Dec 2022, 4:42 AM
A N
A N - avatar
2 Answers
+ 7
A N , independent from the hints* of Brian, there are typos in the output string. > the code uses lowercase 'k' instead of uppercase 'K' (read the task description). after correcting this, your code will run as expected. * surprisingly sololearn is accepting both versions: if purity > 99.9: if purity >= 99.9:
11th Dec 2022, 11:01 AM
Lothar
Lothar - avatar
+ 2
A N Check the logic when purity=99.9 Coding tip: I recommend using elifs after the first if statement. As soon as one of the conditions is true, elif will prevent unnecessarily checking the remaining conditions.
11th Dec 2022, 6:10 AM
Brian
Brian - avatar