Ad
  • Custom User Avatar

    No problem, about using an external var, watch out because it'll keep its value when your function is called more than once, and that'll give you wrong results.

    Thanks again for not giving me the answer but pointing me in the right direction.

    A little push in the right direction is the way to do it. At least for me.

  • Custom User Avatar

    @Chrono79 Thanks again for the help and the great resource you linked. Recursion was happening however since I did not return the recursive function the value was being lost as the recursive stack frames unwind. This was solved by simply returning the recursive function or could have also been solved by using variables declared outside of the function that's state is changed by each recursive call.

    Thanks again for not giving me the answer but pointing me in the right direction.

  • Custom User Avatar

    Try seeing how recursion works with some examples and you'll see what you're doing wrong there.

  • Custom User Avatar

    Because you're doing recursion wrong. See what your code does here: http://www.pythontutor.com/visualize.html#mode=edit

  • Custom User Avatar

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

  • Custom User Avatar
  • Custom User Avatar

    I interpret this to mean that the height of the window where mother is is fixed (i.e, always 1.5). Is this right?

    No, that's an example value, h is a parameter of your function, it's not a fixed value.

    Is window actually the height where the mother is? (which means that that height is not always 1.5, and, so, NOT fixed)

    Yes.

    I'm assuming the ball is dropped from h. Is this right?

    Yes.

  • Custom User Avatar

    So how I understood it is. The h is anything greater than zero, window, where the mother is, value is changing and is greater than zero but less than h, and the ball is dropped from h.

  • Custom User Avatar

    @Chrono79, Thanks you were right. It was because I wasn’t validating all the inputs. I do not know what test case was causing the infinite loop but once I validated all the inputs it fixed the issue. My guess was there was a situation where window was less than 0 and my h value never goes below zero so it created an infinite loop.

  • Custom User Avatar

    When I press ATTEMPT I pass most of the tests but not all. I know there is a problem with my code and that it most likely
    has to do with my interpretation of the instructions. So, I would be grateful if someone could clarify the following:

    Instructions state: "His mother looks out of a window 1.5 meters from the ground."

    I interpret this to mean that the height of the window where mother is is fixed (i.e, always 1.5). Is this right?

    Now, the function bouncingBall has a window parameter (as well as a height parameter, h).
    So, what is the relationship between h and window?
    Is window actually the height where the mother is? (which means that that height is not always 1.5, and, so, NOT fixed)

    I'm assuming the ball is dropped from h. Is this right?

    Anyway, it would be awesome if anyone could shed some light on this.

    Thanks.

  • Custom User Avatar

    It is passing all the test case

    Not exactly, it passes all the tests until it times out with another one. You also have an infinite loop because you didn't validate the input values as per instructions.

  • Custom User Avatar

    There is nothing wrong with the tests, read the instructions again, you're not validating the input and hence your code has an infinite loop.

  • Custom User Avatar

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