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

Alan Gauld alan.gauld at yahoo.co.uk
Sat Jun 20 11:00:18 EDT 2020


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.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/l2p2
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list