Indentation and one more error


Why should we indent return function according to ‘def’ and not according to ‘for’ or ‘if’?
also why is the code showing error on compute_bill?


Hi @textrockstar39356,

The return statement is indented to a degree that enables it to execute after the for loop has completed all its iterations, and therefore the value of total accounts for all the value that need to be added together.

What type of object should be passed to the compute_bill function when it is called, and what information should it contain?


after the return statement ;

print compute_bill(stock[‘banana’ ])

shows error. I just want to know why it is showing error


You need to pass a list to the compute_bill function, for example …

print compute_bill(['banana'])

… or …

print compute_bill(['orange', 'pear', 'banana'])

… or …

print compute_bill(shopping_list)

You passed stock[‘banana’] to the function, instead, which evaluates to the number 6 from the stock dictionary.


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