Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
The given expression can be broken down to
x = expr1
, whereexpr1: 13 + y = 3 + 1
due to the operator'='
's lower prescedence compare to'+'
.Again,
expr1: expr2 = expr3
whereexpr2: 13 + y
,expr3: 3 + 1
. Bothexpr2
andexpr3
are valid expressions ify
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.
oh, ok.
I'm not sure to follow what you're talking about, here... ;o
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.
looks like a fine opinion to me. Let's do it that way, then.
This comment is hidden because it contains spoiler information about the solution
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
that should be good, now.
/
is floor division, ofc)eval
but the fact that floating point errorsaren'tweren't taken care of properlyAfter 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.
Can confirm this. python random tests are just not right. Mainly related to the rounding, it seems like.