[Tutor] Regarding loops

jeremy kearns jk_ksu at budweiser.com
Sat Oct 18 16:17:39 EDT 2003


import random



# create a sequence



WORDS = ("python","jumble",)



# pick a random word



word = random.choice(WORDS)



# create variable to use later to see if guess is correct



correct = word



# jumble creation part



# -------------------------------



# create an empty jumble word

# while the chosen word has letters in it

# extract a random letter from the chosen word

# add the random letter to the jumble word



# jumbled version of the word

jumble = " "

while word:

    position = random.randrange(len(word))

    jumble += word[position]

    word = word[:position] + word[(position + 1):]



# start



print \

"""



            Welcome to the word jumble!



    Unscramble the letters to make a word.

    (press the enter key at prompt to exit)

"""



# PROBLEM AREA



print "The jumble is:", jumble



guess = raw_input("\nYour guess: ")

guess = guess.lower()

while (guess != correct) and (guess != ""):

    if guess != correct and correct == "python":

        print "Do you want a hint?"        

    userHint1 = int(raw_input("1 for True or 0 for False: "))

    if userHint1 == True:

        print "What program is associated with python.org? "

    else:

        print "You guessed wrong, maybe take a hint next time."



    if guess != correct and correct == "jumble":

        print "Do you want a hint?"        

    userHint1 = int(raw_input("1 for True or 0 for False: "))

    if userHint1 == True:

        print " "

    else:

        print "You guessed wrong, maybe take a hint next time."



# I can't get the loops to function properly here.  

# The loops override each other.

# Can you please point out what is wrong with this?



if guess == correct:

    print "That's it! You guessed it!\n"



print "Thanks for playing."

raw_input("\nPress enter to exit the program.")




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20031018/4d73cef9/attachment.html


More information about the Tutor mailing list