HomePagev2 Forums Python Discussions Operators prctice – 2

  • Operators prctice – 2

  • narendra

    Member
    December 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”.

  • Satish Vadlamani

    Administrator
    December 19, 2020 at 2:37 pm

    @narensahu can you please post your code..

    • narendra

      Member
      December 19, 2020 at 2:43 pm

      def state_checker(a):

      res = None

      if a < 0: res = ‘solid’

      elif a < 100: res = ‘liquid’

      else: res = ‘gas’

      return res

  • Satish Vadlamani

    Administrator
    December 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?

  • Trever Ehrlich

    Administrator
    December 19, 2020 at 2:59 pm

    Let us know if you’re not able to solve it, narenda. Might have to double-check the autobot.

  • Satish Vadlamani

    Administrator
    December 19, 2020 at 3:12 pm

    @narensahu actually your code looks like correct, ignoring edge cases. I tested this and it is working.

    def state_checker(a):
       res = None
       if a < 0: 
          res = 'solid'
       elif a < 100: 
          res = 'liquid'
       else: 
          res = 'gas'
       return res
    • narendra

      Member
      December 19, 2020 at 3:52 pm

      I also tested in Atharva IDE coder and the results are as expected. But running in the quiz section, showing ‘incorrect’

  • Satish Vadlamani

    Administrator
    December 19, 2020 at 3:56 pm

    @narensahu thank you. @trever-ehrlich is looking into it

  • Trever Ehrlich

    Administrator
    December 20, 2020 at 1:17 am

    @narensahu and @satish-vadlamani , the problem is resolved. I apologize for the inconvenience. Try again, your code works correctly. That’s what happens when I program past midnight!!

Log in to reply.

Original Post
0 of 0 posts June 2018
Now