The main thing your program lacks is flexibility. Adding new puzzles requires chaining together a series of if..else statements and creating variables for each hint. <br><br>Here's my quick version. I store the puzzles and the hints in a two-tuple sequence. Following this method you could easily add additional hints for each puzzle.
<br><br> (I changed up the scoring system a bit too...just my spin on it)<br><br>import random<br> <br># create a series of puzzles to choose from<br>puzzles = (("python","It's the best programming language for the absolute beginner ..."),
<br> ("jumble","It's what this program does to words to make it difficult to guess them ..."),<br> ("easy","It's not difficult ..."),<br> ("difficult","It's not easy ..."),
<br> ("answer","It's not a question ..."),<br> ("xylophone","It's a musical instrument you have to hit with 2 small sticks ..."))<br> <br>
<br># pick one word randomly from the sequence<br>which_puzzle = random.choice(range(len(puzzles)))<br>correct_word = puzzles[which_puzzle][0]<br>jumbled_word = list(correct_word)<br>hint = puzzles[which_puzzle][1]<br><br>
random.shuffle(jumbled_word)<br>jumbled_word = ''.join(jumbled_word)<br><br>print \<br>"""<br> Welcome to Word Jumple!<br> <br> Unscramble the letters to make a word.<br> (Press the enter key at the prompt to quit.)
<br>"""<br><br> <br>score = 0<br>while 1:<br> print "The jumble:", jumbled_word<br> guess = raw_input("\nYour guess: ")<br> guess = guess.lower()<br> <br> if guess == '':
<br> break<br><br> if guess != correct_word:<br> print "Sorry that's not it."<br> hint_prompt = raw_input("Would you like a hint? Y/N: ")<br> hint_prompt = hint_prompt.lower()
<br> if hint_prompt.startswith('y'):<br> print hint+"\n"<br> score -= 50<br> <br> if guess == correct_word: <br> score += 200<br> print "\nThat's it! You guessed it!\n"
<br> if score == 200:<br> print "Because you never asked for a hint you get %d points.\n" % (score)<br> else:<br> print "Since you asked for a hint or two you're score is %d points.\n" % (score)
<br> break<br> <br> <br>print "\nThanks for playing."<br> <br><br><div><span class="gmail_quote">On 4/17/07, <b class="gmail_sendername">Alexander Kapshuk</b> <<a href="mailto:akap@isd.dp.ua">
akap@isd.dp.ua</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-AU">
<div>
<p><font face="Verdana" size="2"><span style="font-size: 10pt; font-family: Verdana;">Hello Everyone,</span></font></p>
<p><font face="Verdana" size="2"><span style="font-size: 10pt; font-family: Verdana;"> </span></font></p>
<p><font face="Verdana" size="2"><span style="font-size: 10pt; font-family: Verdana;">This is Alexander Kapshuk writing here again …</span></font></p>
<p><font face="Verdana" size="2"><span style="font-size: 10pt; font-family: Verdana;"> </span></font></p>
<p><font face="Verdana" size="2"><span style="font-size: 10pt; font-family: Verdana;">Could you please have a look at the code below and let me
know of any shortcuts that could be used there.</span></font></p>
<p><font face="Verdana" size="2"><span style="font-size: 10pt; font-family: Verdana;"> </span></font></p>
<p><font face="Verdana" size="2"><span style="font-size: 10pt; font-family: Verdana;">The code works fine as it is. I was just wandering if there
was a better, more compact and elegant way of writing the program.</span></font></p>
<p><font face="Verdana" size="2"><span style="font-size: 10pt; font-family: Verdana;"> </span></font></p>
<p><font face="Verdana" size="2"><span style="font-size: 10pt; font-family: Verdana;">Thanking you all in advance.</span></font></p>
<p><font face="Verdana" size="2"><span style="font-size: 10pt; font-family: Verdana;"> </span></font></p>
<p><font face="Verdana" size="2"><span style="font-size: 10pt; font-family: Verdana;">Alexander Kapshuk</span></font></p>
<p><font face="Verdana" size="2"><span style="font-size: 10pt; font-family: Verdana;"> </span></font></p>
<p><font face="Verdana" size="2"><span style="font-size: 10pt; font-family: Verdana;"> </span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"># Word Jumble Game</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">#</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"># The computer picks a random word and
then "jumbles" it.</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"># The player has to guess the original
word.</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">#</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"># Should the player be stuck and require
a hint, they will be prompted for a hint.</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"># If the player answers 'yes', the
appropriate hint will be displayed and the player will be asked to guess again.</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"># If the player answers 'no', they will
be asked to guess again and awarded some points if they manage to guess the jumbled
word without ever asking for a hint.</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> </span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">import random</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> </span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"># create a sequence of words to choose
from</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">WORDS = ("python",
"jumble", "easy", "difficult",
"answer", "xylophone")</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> </span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"># pick one word randomly from the
sequence</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">word = random.choice(WORDS)</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> </span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"># create a variable to use later to see
if the guess is correct</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">correct = word</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> </span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"># create hints for all the jumbled words</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">hint0 = "\nIt's the best
programming language for the absolute beginner ...\n"</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">hint1 = "\nIt's what this program
does to words to make it difficult to guess them ...\n"</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">hint2 = "\nIt's not difficult
...\n"</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">hint3 = "\nIt's not easy
...\n"</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">hint4 = "\nIt's not a question
...\n"</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">hint5 = "\nIt's a musical
instrument you have to hit with 2 small sticks ...\n"</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> </span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"># create a jumbled version of the word</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">jumble = ""</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> </span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">while word:</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> position =
random.randrange(len(word))</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> jumble +=
word[position]</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> word =
word[:position] + word[(position + 1):]</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> </span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"># start the game</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">print \</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">"""</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">
Welcome to Word Jumple!</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> </span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> Unscramble the
letters to make a word.</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> (Press the enter key
at the prompt to quit.)</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">"""</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">print "The jumble:", jumble</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> </span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">guess = raw_input("\nYour guess:
")</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">guess = guess.lower()</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">score = 0</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">while (guess != correct) and (guess !=
""):</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> print "\nSorry,
that's not it.\n"</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> hint_prompt =
raw_input("Would you like a hint? Y/N: ")</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> hint_prompt =
hint_prompt.lower()</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> if hint_prompt ==
"yes" and correct == WORDS[0]:</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">
print hint0</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> elif hint_prompt ==
"yes" and correct == WORDS[1]:</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">
print hint1</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> elif hint_prompt ==
"yes" and correct == WORDS[2]:</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">
print hint2</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> elif hint_prompt ==
"yes" and correct == WORDS[3]:</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">
print hint3</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> elif hint_prompt ==
"yes" and correct == WORDS[4]:</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">
print hint4</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> elif hint_prompt ==
"yes" and correct == WORDS[5]:</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">
print hint5</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> elif hint_prompt ==
"no":</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">
score += 50</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> </span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> guess =
raw_input("Your guess: ")</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> guess = guess.lower()</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> </span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> if guess == correct
and hint_prompt == "no":</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">
print "\nThat's it! You guessed it!\n"</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">
print "Because you never asked for a hint you get", score,
"points.\n"</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> </span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">print "\nThanks for playing."</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> </span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);">raw_input("\n\nPress the enter key
to exit.")</span></font></p>
<p><font color="#333399" face="Times New Roman" size="3"><span style="font-size: 12pt; color: rgb(51, 51, 153);"> </span></font></p>
</div>
</div>
<br>_______________________________________________<br>Tutor maillist - <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Tutor@python.org">Tutor@python.org</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">
http://mail.python.org/mailman/listinfo/tutor</a><br><br></blockquote></div><br>