[Tutor] [maryknauth at mac.com: Re: Input parameters for functions]

Mats Wichmann mats at wichmann.us
Sat Jun 20 11:17:23 EDT 2020


On 6/20/20 9:00 AM, Alan Gauld via Tutor wrote:
> On 20/06/2020 14:08, Mary Knauth via Tutor wrote:
>>  I think I need to add return to my functions.
> 
> That's correct.
> 
>> ‘return account_balance = account_balance + deposit_amount’ is an invalid syntax, 
> 
> Yes. You cannot combine assignment and another statement such as return.
> (In the latest versions of Python there is a new feature that does allow
> this but we will ignore that for now!)
> 
> You need to calculate the value first then return it.
> 
> account_balance = account_balance + deposit_amount
> # possibly do more things with account_balance
> return account_balance
> 
> 
> If you don;t need to do anything with account_balance you can return the
> calculation result directly:
> 
> return account_balance + deposit_amount
> 
> You may find the "Modules and Functions" topic of my tutorial helpful.


I think you'll also find that this example will make more sense in a
context that will come up later in your learning: a way to have
persistent values that can be accessed by functions, without using
global variables, will be laid out when the course gets on to classes
and methods ("object oriented programming", although in Python it's all
objects actually). Have to lay the foundation first, though.






More information about the Tutor mailing list