0
#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.
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")
+ 1
Thank you Python Learner. I got it :)
0
Thak you for your comment
Python for begginers
22.2
Pure gold
Does this work?