+ 3

Boolean Logic — Gold Purity

#trying to see what I did wrong with this code. Only getting one output for (18K).. purity = float(input()) if purity == 75.0 or 83.3 : print("18K") elif purity == 83.3 or 91.7 : print("20K") elif purity == 91.7 or 99.9 : print("22K") elif purity == 99.9 : print("24K")

3rd Feb 2021, 10:04 PM
Davon
Davon - avatar
6 Réponses
+ 5
# anyway, in python (guess by your code), you could shorten the last 'and' statement to: if 75.0 <= purity < 83.3:
3rd Feb 2021, 10:26 PM
visph
visph - avatar
+ 3
If you still need the code, I tried this and it worked for me purity = float(input()) #your code goes here if purity >= 99.9: print("24K") elif purity >= 91.7 and purity < 99.9: print("22K") elif purity >= 87.5 and purity < 91.7: print("21K") elif purity >= 83.3 and purity < 87.5: print("20K") elif purity >= 75.0 and purity < 83.3: print("18K")
24th Apr 2021, 5:40 PM
Mukhtar Al Maden
+ 2
if purity == 75.0 or purity == 83.3: # at least, plus simalar in elif statement to be valid... """ however, you probably need something like: """ if 75.0 <= purity and purity < 83.3: # to check range instead of just two values...
3rd Feb 2021, 10:15 PM
visph
visph - avatar
+ 2
#I think stating a range will help your code purity = float(input()) if 75.0 <= purity <= 83.3: print(“18K”) #etc
14th Feb 2021, 5:56 PM
Kaiaiak
Kaiaiak - avatar
+ 1
thanks Mukhtar Al Maden! I was stuck on that for so long and that code worked perfectly.
6th Sep 2021, 8:45 AM
Kyle Costain
Kyle Costain - avatar
- 1
Hello Mukhtar Al Maden I have some questions about your code above: Why did you use "21K" and 87.5... I mean... where that info came from? I hope you can answer because I am still struggling to understand this test.
17th Jun 2021, 3:24 PM
Alberto Malvado
Alberto Malvado - avatar