Python: Control Flow, 22.2 Practice, Pure Gold | Sololearn: Learn to code for FREE!


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

4/19/2021 10:44:18 PM


2 Answers

New Answer


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!


the correct code covering all 5 cases: purity = float(input()) if purity >= 91.7: print("Accepted") if purity == 99.9: print("Accepted")