Python: Control Flow, 22.2 Practice, Pure Gold | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 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 :)

19th Apr 2021, 10:44 PM
Walnut
2 Respuestas
+ 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!
19th Apr 2021, 10:53 PM
Paula Campbell
Paula Campbell - avatar
+ 2
the correct code covering all 5 cases: purity = float(input()) if purity >= 91.7: print("Accepted") if purity == 99.9: print("Accepted")
9th Jun 2021, 10:19 AM
Alexandru Serbanescu
Alexandru Serbanescu - avatar