what is the sample answer for this section? my code is not printing anything but there is the green tick ???
By default, a function returns None at the end of the function. If we want to return something else at the end of the function, we can use the return keyword.
Given return is the last thing a function does, when a return keyword is reached, the function ends
so the print statement you put is never reached, plus, for a function to execute, you need to call it. Plus, if you want to print the returned result, put a print statement before the function call
so if i want the function to print the total for the shopping_list, do i add in print compute_bill(shopping_list) right before return total?
this is the better approach, by putting
what is function call? i m kinda getting confused with all these terms = =
line 26 in your code. The function call executes the function.
functions are sort of like task lists, a set of instructions which need doing but not right now, maybe later, or not at all.
the function call is what triggers the function (going about doing the task lists)
# function deceleration def example(): print "hello world" # function call example()
you can recognize the function call by its matching function name, but without the
you have used many function calls already at this point, like
len(). So someone defined a function within python somewhere, which gives you the length.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.