Is it the Same?


#1




Hi, I was just wondering if someone could verify whether the two functions below give the same result for all input. Are there specific values where it might give a different result?


Case 1:

def rental_car_cost(days):
    if days >= 7:
        return (40 * days) - 50
    elif days >= 3:
        return (40 * days) - 20
    else:
        return 40 * days

Case 2:

def rental_car_cost(days):
    cost = 40 * days
    if days >= 7:
        cost -= 50
    elif days >= 3:
        cost -= 20
    return cost

Thank you!


#2

Hi @objectsolver22460 ,

Perform a test to find out.

Rename one of the functions. Then write a loop that iterates through the ints in the range from 0 to 10.

Within the loop, pass each int to both functions, print the results, and compare.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.