[Tutor] Word Jumble - Chpt4 (Explanation)

Alan Gauld alan.gauld at btinternet.com
Fri May 17 02:56:55 CEST 2013


On 16/05/13 21:03, Arvind Virk wrote:

> This is my first post so go gentle. I'm just getting into Python
> programming and am having an issue understanding the Word Jumble Game.

Welcome.
First thing is we have no idea what Chapter 4 refers to so please tell 
us the source you are working from (alsoi OS and Python version helps too)
Secondly tell us what happens when you run it and what you expected and 
what you got and why you are surprised/puzzled.


> import random
>
> WORDS = ('python','jumble','easy','difficult','lower','high')
> word = random.choice(WORDS)
> correct = word

FWIW I don't understand the above line. It does nothing useful and 
correct is not used again...

> jumble = ""
>
> while word:
>      position = random.randrange(len(word))
>      jumble += word[position]
>      word = word[:position] + word[(position+1):]
>

Also since there are no print statements it all seems a tad pointless, 
are you sure that's the whole program?


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



More information about the Tutor mailing list