I would sat that using multiple if statements is a slightly better practice over if ... elif ... elif ... whenever the condition for all of the ifs is both consistent and clearly exclusionary. In this case, both of those are met since it is an inate logical idea in programming that if a variable equals a character, then it cannot also equal a different character.
Using only if statements makes the code sligtly easier to read, especially for those who use any of the braced langagues (Java, C#, JavaScript, etc) where you have to use if (condition) {...} else if (condition) {...} else if (condition) {...} else {...} instead of elif.
But I 100% agree that using a ternary instead of just returning an equality expression is not a best practice.
This seems like a typo in one of the internal tests. I believe the test is missing a slash ('/') between the stars. As it stands, the test is requiring that a single star be treated as the start of a comment.
I would sat that using multiple
if
statements is a slightly better practice overif ... elif ... elif ...
whenever the condition for all of the ifs is both consistent and clearly exclusionary. In this case, both of those are met since it is an inate logical idea in programming that if a variable equals a character, then it cannot also equal a different character.Using only
if
statements makes the code sligtly easier to read, especially for those who use any of the braced langagues (Java, C#, JavaScript, etc) where you have to useif (condition) {...} else if (condition) {...} else if (condition) {...} else {...}
instead ofelif
.But I 100% agree that using a ternary instead of just returning an equality expression is not a best practice.
.
Nope. Try print(code) to see test case.
My appologies. New format is also available, and I belive preferred, in 2.7 as well.
See https://docs.python.org/2.7/library/string.html#string-formatting
Codewars uses Python 2.7
Test Failurer: '1 ** b */ 1' should equal '1 * 1'
This seems like a typo in one of the internal tests. I believe the test is missing a slash ('/') between the stars. As it stands, the test is requiring that a single star be treated as the start of a comment.
This comment is hidden because it contains spoiler information about the solution
It fails for this:
Testing for 536878877
It should work for random inputs too - Expected: 144119464552830000, instead got: 144119464351499500
It's doesn't perform the final test
All tests pass except for this one:
Failing test: 144991 should equal 'Error 404'
Even forcing an
if int(x) == 144991: return 'Error 404'