MemberDecember 19, 2020 at 2:29 pm
Hello, fellow Shishyas,
Operators practice – 2 is a very simple problem that can be solved using the if-elif-else condition. However, when I am submitting, it’s showing the answer isn’t correct. Am I missing something obvious. Need suggestions.
problem: H20 freezes below 0C, and steams above 100C. For a given temperature, return the state of the H20 – “solid”, “liquid”, or “gas”.
AdministratorDecember 19, 2020 at 2:37 pm
@narensahu can you please post your code..
AdministratorDecember 19, 2020 at 2:50 pm
Assuming your indentation is correct in the real code.( BTW you can indent here as well. ).
You have tow conditions a<0 and a<100..which returning two different things… That is not correct. Maybe change the second condition to be greater than 0 and less than 100? Also, you have to think about <= as well. Because ice is <= 0, correct?
AdministratorDecember 19, 2020 at 3:12 pm
@narensahu actually your code looks like correct, ignoring edge cases. I tested this and it is working.
res = None
if a < 0:
res = 'solid'
elif a < 100:
res = 'liquid'
res = 'gas'
Log in to reply.