Ad
  • Custom User Avatar

    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.

  • Custom User Avatar

    @Voile: what's your opinion on how to resolve this?

    • Leaving strings aside and use approx equality?
    • enforcing precise calculations? (how?)
    • just drop the idea/kata?
    • something else?
  • Custom User Avatar

    the inputs you give do not lead to the output you're talking about => ?

    I forgot a multipler on days. For

    before = 0.1
    after = 0.2
    days = 3 * 365
    

    Some calculations gives 0.0375 while some gives 0.037500000000000006, which rounds to 0.037 and 0.038 respectively.

    Moreover, if you use

    before = 0.1
    after = 0.6
    days = 3 * 365
    

    Then it's easier to get the exact result of 0.0875, which also rounds down to 0.087.

  • Custom User Avatar

    because that's a code working only for python 2

  • Custom User Avatar

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

  • Custom User Avatar

    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!

  • Custom User Avatar

    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 => ?

  • Custom User Avatar

    This code doesn't seem to pass when I copy and paste it.
    range(1, 6) should equal [1, 2, 3, 4, 5]

    ?

  • Custom User Avatar

    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

  • Custom User Avatar

    Thanks. As all the random tests passed I thought it would be ok. What would you recommend - no rounding at all?

  • Custom User Avatar

    rounded to three decimal places

    As usual, this is not recommended because of floating point errors. Example:

    before = 0.1
    after = 0.2
    days = 365
    

    This equals 0.0375 years, but rounds down to 0.037 due to floating point error.