+ 10
SOLVED 24K magic exercise in python for beginners - HELP
The task is to have the karat displayed for an inputted purity of gold. If the purity is under 75%, nothing should display. I'm getting all of the test cases right except the last with the below code, what am I doing wrong? purity = float(input()) if purity >= 99.99 and purity <= 100: print("24K") elif purity >= 91.7: print("22K") elif purity >= 83.3: print("20K") elif purity >= 75.0: print("18K")
28 odpowiedzi
+ 12
Remove the 'and' operator and the rest in your first condition.
Everything will be fine.
So, Your code needs to be
purity = float(input())
if purity >= 99.99:
print("24K")
elif purity >= 91.7:
print("22K")
elif purity >= 83.3:
print("20K")
elif purity >= 75.0:
print("18K")
+ 6
🇮🇳 R😻 thanks for the responses. I tried that and it's still not working for the last test case. Wish I knew what the test case is!
+ 5
Zoë did you wrote 99.9 or 99.99?
+ 2
Abhay THANK YOU! That's exactly where I went wrong, all working now.
+ 2
Zach Z I had to change 99.99 to 99.9.
+ 1
The code in the question is my attempt:
purity = float(input())
if purity >= 99.99 and purity <= 100:
print("24K")
elif purity >= 91.7:
print("22K")
elif purity >= 83.3:
print("20K")
elif purity >= 75.0:
print("18K")
+ 1
Zoë Rillstone Run your code in Code Playground then add it in your question
+ 1
Abhay Posting question with proper format is good thing that's why I said that
+ 1
Zoë In condition if the purity is under 75% nothing should display print(" ")
+ 1
Simba I'm still getting the error on the last test case.
+ 1
Mohasin Haque don't spam
+ 1
Bro remove "and purity <= 100"
You can add one more line in code to for invalid input(more than 100)
Elif purity >100 :
Print("invalid input please inter between range of 0 to 100")
+ 1
"if purity>=99" that includes the upper range up to 100%...actualy ">=" it means that "greator than or equal to"
...
Later on, try to have them in a single print function#
+ 1
A Simple Guy (New Id) done now - sorry, I'm a complete noob!
+ 1
Zoë how did you get the last test case to work?
+ 1
First two's answers need to be "Accepted"
This was my solution and it worked for all the tests:
purity = float(input())
if purity >= 99.99:
print("Accepted")
elif purity >= 91.7:
print("Accepted")
elif purity >= 83.3:
print("20K")
elif purity >= 75.0:
print("18K")
0
Zoë Rillstone Show your attempt
0
🇮🇳 R😻 why should they run code in playground and then add it to question ?