#python #user input #if statement

Please help me to write a code to inspect the purity of gold. I want to lead the output ‚ÄúAccepted‚ÄĚ if the purity satisfies more than 91.7 percent of gold which means it corresponds 22k or 24k. 22k has 91.7 percent of gold or more gold in it while 24k corresponds 99.9 percent and above purity. My code purity = input(‚ÄúAccepted‚ÄĚ) if purity >= str(91.7): print(purity) However, when the input is 94.7, output becomes strings of Accepted and input number, like Accepted94.7 I want to display only Accepted.

16th Aug 2021, 4:45 PM
3 Respostas
+ 4
Hi YokoS! You're mixing input prompt message with output variable. You can use prompt message to give information about your code whereas output variable is the result of your code. It's always better to use float() to handle decimal values. Here, you're using str() in if statement. So, it compares ascii value instead of numeric value because of str(). It can give output as "Accepted" even if input is a string. These are the things you have to consider in your code. Here it is your working code. purity = float(input()) if purity > (91.7): print("Accepted")
16th Aug 2021, 5:40 PM
Python Learner
Python Learner - avatar
+ 1
Thank you Python Learner. I got it :)
16th Aug 2021, 5:51 PM
Thak you for your comment Python for begginers 22.2 Pure gold Does this work?
16th Aug 2021, 5:10 PM