Hi @jgraddon5 ,
Both of your
rental_car_cost function examples exemplify reasonable and common strategies for computing and
returning a result. However, as @mtf states, the submission correctness test that the author of the exercise created might be particular regarding which, among many possible correct solutions, it will accept.
Note that both of your examples need some correction, although in the case of the second one, the problem might not be obvious, and may not even have caused the code to malfunction.
The first example is designed to compute and
return a result in each conditional block, and includes a default
return value in the final line of the function. Of course, for any given call of the function, only one of the
return statements would execute, depending upon which condition is applicable, and that is fine.
However, the two
return statements within the conditional blocks contain enhanced assignment operators, and that is an error. For example, this …
return cost -= 50
… should be …
return cost - 50
That is why the SCT would not accept the first submission.
The second example computes a result within whatever conditional block applies, and
returns a value at the end, so all calls to the function eventually terminate when the final line is reached.
Another important issue is that in the first example, this statement utilizes two spaces followed by a tab for indentation …
return cost -= 20
… and the same is true of this statement in the second example …
cost -= 20
Using a mixture of tabs and spaces for indentation in a Python program should be avoided, and usually leads to problems, even if it did not do so in this case.