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.
Precise calculation in a string is possible if the user accepts a ratio 'n/d' instead of a rounded number. Since the input 'before' and 'after' are also floating point, they should also be presented as ratios. On the other hand, there is no added value in returning a string in this kata.
@Voile: what's your opinion on how to resolve this?
I forgot a multipler on
days
. ForSome calculations gives
0.0375
while some gives0.037500000000000006
, which rounds to0.037
and0.038
respectively.Moreover, if you use
Then it's easier to get the exact result of
0.0875
, which also rounds down to0.087
.because that's a code working only for python 2
This comment is hidden because it contains spoiler information about the solution
Definitely I could remove the string output - just thought it was maybe a bit of a way to flex some beginner f'strings in 7-8kyu at the same time but maybe just overcomplicates it. This is my first Kata so learning this as I go. Thanks for the feedback!
note: Actually, I think there is only one way to compute the correct result, in the case of your kata, so it's not about approximate equality.
@Voile: the inputs you give do not lead to the output you're talking about => ?
This code doesn't seem to pass when I copy and paste it.
range(1, 6) should equal [1, 2, 3, 4, 5]
?
the nromal course of action with floating point errors is to use approximate equality. But that suppose to have numbers as output (...that's where "you" realize that strings aren't a good output when you're actually interested in numbers)
=> requires to change the output type
Thanks. As all the random tests passed I thought it would be ok. What would you recommend - no rounding at all?
As usual, this is not recommended because of floating point errors. Example:
This equals
0.0375
years, but rounds down to0.037
due to floating point error.