+ 4
Python: Control Flow, 22.2 Practice, Pure Gold
Iâm not sure how to solve the âPure Goldâ task under 22.2 Practice for Control Flow in Python. I keep getting â93.4Acceptedâ as the output, instead of just âAcceptedâ which is what the answer should be. My code is: purity = float(input(93.4)) if purity >=91.7: print(âAcceptedâ) if purity <=99.9: print(âAcceptedâ) Also, is there a faster way to code something like this for example: if purity in range(91.7, 99.9): print(âAcceptedâ) The above code doesnât work, any idea why? Thanks :)
2 RĂ©ponses
+ 6
The reason why your code isn't working is pretty simple: when you call input function with an argument, like you did when you said purity = float(input(93.4)) the argument will be printed out to the console. And I'm sure that that was not what you were looking for! If you remove the parameter when you call that function, you will get as a result "Accepted" instead of "93.4Accepted".
On your second question, I would suggest you to try the following code:
purity = float(input())
if purity >=91.7 and purity <=99.9:
print(âAcceptedâ)
Hope this helps!
+ 2
the correct code covering all 5 cases:
purity = float(input())
if purity >= 91.7:
print("Accepted")
if purity == 99.9:
print("Accepted")