Ad
  • Custom User Avatar

    The given expression can be broken down to x = expr1, where expr1: 13 + y = 3 + 1 due to the operator '=''s lower prescedence compare to '+'.
    Again, expr1: expr2 = expr3 where expr2: 13 + y, expr3: 3 + 1. Both expr2 and expr3 are valid expressions if y is already assigned.
    However, even if expr2 could be resolved, expr1 would end up being an invalid expression, since '=' operator only takes an identifier on the left-hand side.

    tl;dr: the expression should cause an error.

  • Default User Avatar
  • Default User Avatar

    I'm not sure to follow what you're talking about, here... ;o

  • Custom User Avatar

    Oh I didn't see the problem is for py2, thank you for the correction.
    In py2 though, eval() function would work the same as py3 if the test generator gives floating numbers.

  • Default User Avatar

    looks like a fine opinion to me. Let's do it that way, then.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Hi FArekkusu,

    I had to update your python version because it didn't handle correctly floating point errors (your idea to use round was pretty bad. It's actually the worst thing you could have think about ;) ). I strongly advise that you take a look at the way I did it, that could be of use to you later.

    Note that your internal solution as some flaw too: I ended up with one error in the random tests (but I don't have the input). Fortunately, the errors are rare so I've been able to republish without pushing my solution instead of yours. Would be a good idea that you dig into that to get a fully correct solution.

    cheers,
    B4B

  • Default User Avatar

    that should be good, now.

  • Default User Avatar
    • you're supposed to do the calculations in py3, absolutely NOT in py2 (unless you handle properly the fact that / is floor division, ofc)
    • the problem isn't the use of eval but the fact that floating point errors aren't weren't taken care of properly
    • I updated the tests, that should be good now.
  • Custom User Avatar

    After struggling for hours, figured out that python (2.7 in my case, but probably for all versions if it uses the same test code) test case is totally wrong.
    It uses eval(expression) to calculate the given expression, however the expression is all chosen with randint function.
    In other words, input expression would always only contains integers, so that eval always rounds off decimals.
    If you want to pass the random tests for now, just use integers, negelecting floating numbers.

  • Custom User Avatar

    Can confirm this. python random tests are just not right. Mainly related to the rounding, it seems like.