[Tutor] Need help with functions!

Alan Gauld alan.gauld at btinternet.com
Tue Jan 26 09:32:28 CET 2010


"Raymond Kwok" <blurayhk at yahoo.com.hk> wrote

> I have a function called get_word() that does the random word thing and
> returns two things - 1) original word and 2) scrambled word, 
>
> jumble = get_word()[0]
> originalword = get_word()[1]

You need to store the return value once and access the two values.

words = get_word()
jumble = words[0]
originalword = words[1]

OR, use the neat Python trick of unpacking into two variables at 
once, like this:

jumble,original_word = get_word()

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list