[Tutor] Beginner can't finish code
Tamaryn Sarusi-Kiss
tamarynsarusi-kiss at optusnet.com.au
Thu Mar 30 03:52:11 CEST 2006
Hi,
I'm a beginner and can't finish the code I'm working on below. I want
the code below to have "hints" when the user asks for them , and I don't
know enough to do this.What would be the best way of introducing "hints" and
allowing the user to exit when he wants to. Any help would be appreciated.
The Word Jumble Game
>> import random
>>
>> # create a sequence of words to choose from
>> WORDS = ("python", "easy")
>> # pick one word randomly from the sequence
>> word = random.choice(WORDS)
>> # create a variable to use later to see if the guess is correct
>> correct = word
>> # create variable to use for hint if needed
> hint = "hint"
>> # create a jumbled version of the word
>> jumble =""
>> while word:
>> position = random.randrange(Len(word))
>> jumble += word[position]
>> word = word[:position] + word[(position + 1):]
>>
>> # start the game
>> print \
>> """
>> Welcome to Word Jumble!
>>
>> Unscramble the letters to make a word.
>> (Press the enter key at the prompt to quit.)
>> """
>> print "The jumble is:", jumble
>> print "If you need a hint type 'hint' and Hit enter."
>> guess = raw_input("\nYour guess: ")
>> guess = guess.lower()
>> while (guess != correct) and (guess != "")and (guess != hint):
>> print "Sorry, that's not it."
>> guess = raw_input("Your guess: ")
>> guess = guess.lower()
>> if guess == hint:
>> print "not hard but"
>> guess = raw_input("Your guess: ")
>> guess = guess.lower()
>>
>> while word == python:
> hints = {'easy':'not hard but','python':'snake'}
> if guess == hint:
> print hints[correct]
> guess = raw_input("Your guess: ")
> guess = guess.lower()
>>
>> if guess == correct:
>> print "That's it! You guessed it!\n"
>>
>> print "Thanks for playing."
>>
>> raw_input("\n\nPress the enter key to exit.")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060330/107da91b/attachment-0001.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 20284 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20060330/107da91b/attachment-0001.gif
More information about the Tutor
mailing list