Ad
  • Default User Avatar

    Mutability. Mutable objects can be changed. Immutable objects cannot.

    p0 is immutable because it is an integer. It is reassigned with each iteration, not mutated.

    The test code calls this function with:
    Test.assert_equals(nb_year(1500, 5, 100, 5000), 15)
    1500 was not harmed during the execution of this function.

    If you assigned p0 to the value 1500 and then passed p0 in the calling function, p0 would still point to 1500 upon funtion completion.

    If you want a funtion to change your objects, pass a mutable object, like a list.

    Generally, if x = [], then x[0] = 1 (mutating) and x = [1] (reassigning) are two different operations. both x-es have the same value, but the mutating version will change x in the calling function, and the assignment has local scope.

    Please correct me if I am wrong.

  • Custom User Avatar
  • Custom User Avatar

    The . just makes it into a float correct? Same function as 100.0?

  • Custom User Avatar

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

  • Default User Avatar

    changing incoming parameters is unacceptable (can has fluense to other part of your app)
    calculation for percent / 100. is slowing down computation in the loop

    Shorter code is not always faster