29 Answers
New AnswerThe 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")
2/15/2021 10:18:14 AM
Zoë29 Answers
New AnswerRemove 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")
🇮🇳 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!
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")
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")
"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#
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")
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message