I am having some very vain attempts to try and learn Python... And have been reading through Mike Dawson's 'Python Programming for the absolute beginner' (Thats me!
I have got to page 155 (Hozar!) and I am attempting the challenges... This one has stumped me:
Create a program that prints a list of words in random order. The Program should print all the words and not repeat any...
I know that you are all going to think that this is easy.... I am A NOOB!
Please can someone help me?
That's a great book, although my copy is at work at the moment.
What I do remember is that the challenges are always at the end of a chapter, and they always involve a modest rearrangement or expansion of the code built up throughout the chapter. You should really already have everything you need to solve the problem. That's the way that book is written.
Look back through the chapter again and try to figure out how what you learn in it could be used to solve the challenge. If we help you too much, it will defeat the object of the challenge (although we do, of course, always try to help anyone who is utterly and completely stuck).
But in general...
First, just create a list of words (say twenty) and print them out one by one in the order in which they are stored. That tests that your list is good.
Then make a way to pick words out of the list in a random order until twenty have been displayed. Don't worry about whether they have already been picked. At this stage some words will be picked more than once and some not at all.
Next, each time you pick a random word from the list, mark it in some way to signify that it has already been picked. The easiest way might be to delete each word from the list as you pick it so it can't be picked again, until eventually the list is empty.