[Tutor] Need help with functions!

Raymond Kwok blurayhk at yahoo.com.hk
Tue Jan 26 08:40:19 CET 2010


Hello all,

I have started to learn Python a few months ago and I'm loving it! 
I
am creating a mini-game - the one that scrambles an English word and
asks you what the originalword should be, e.g. yhptno ---> python 

So,
I have a function called get_word() that does the random word thing and
returns two things - 1) original word and 2) scrambled word, namely
"originalword" and "jumble" respectively.  So every time I run the
get_word() function, it gives me a new word.  

The code is: 

jumble = get_word()[0]
originalword = get_word()[1]
print (jumble)
answer = input ("What do you think this word is? ")
while answer != originalword:          
    answer = input ("No! Guess again please.")
print ("\nThat's right! The word
 is",originalword)

The
while loop keeps running until the user guesses the right answer and it
will display the original word.  The thing is when it shows the
original word, it has in fact become a new word since the "get_word()"
function has been run again and returned a new word.  Does anyone know
how to solve this problem ? I hope it is not too confusing...

-Ray



      Yahoo!香港提供網上安全攻略,教你如何防範黑客! 請前往 http://hk.promo.yahoo.com/security/ 了解更多!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100126/8885c04c/attachment.htm>


More information about the Tutor mailing list