Boolean Logic — Gold Purity | Sololearn: Learn to code for FREE!

+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")

2/3/2021 10:04:14 PM

Davon

+6

# anyway, in python (guess by your code), you could shorten the last 'and' statement to: if 75.0 <= purity < 83.3:

+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...

+2

#I think stating a range will help your code purity = float(input()) if 75.0 <= purity <= 83.3: print(“18K”) #etc

+1

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")

+1

thanks Mukhtar Al Maden! I was stuck on that for so long and that code worked perfectly.

-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.