[Tutor] Regarding loops
Gregor Lingl
glingl at aon.at
Sun Oct 19 05:31:42 EDT 2003
jeremy kearns schrieb:
...
> Welcome to the word jumble!
> ...
> # 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?
Hi Jeremy!
I think you expect this loop to terminate, if the user guessed right.
But in your code the user has only one possibility to give an input
for the
guess. That is before entering the loop. In the body of the loop there is
no assignment of a new value to guess.
To give the user the opportunity to input a new guess, you should add
an appropriate raw_input() call to the body of the loop.
moeover I observed that yuo loop consist of two parts, that are almost
equal.
There is only one line which is different: that printing the hint.
Perhaps you
could find a way to make your code more compact by putting only this line,
depending on the value of correct in (one or two) appropriate if
statement(s)?
Hope this helps?
Gregor
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
More information about the Tutor
mailing list