Wikibooks example doesn't work8

Andrew Christianson Andrew.Christianson at Ipsos.com
Wed Aug 6 23:43:00 EDT 2014


The if statement in question isn't inside the while loop.

White space and indentation is meaningful in python, so putting the if count > 3 block at same indentation as the while statement effectively places it outside the loop.

Regards,

Drew
-------- Original message --------
From: Seymore4Head
Date:08/06/2014 20:32 (GMT-08:00)
To: python-list at python.org
Subject: Re: Wikibooks example doesn't work

On Wed, 06 Aug 2014 22:58:51 -0400, Seymore4Head
<Seymore4Head at Hotmail.invalid> wrote:

>number = 7
>guess = -1
>count = 0
>
>print("Guess the number!")
>while guess != number:
>    guess = int(input("Is it... "))
>    count = count + 1
>    if guess == number:
>        print("Hooray! You guessed it right!")
>    elif guess < number:
>        print("It's bigger...")
>    elif guess > number:
>        print("It's not so big.")

The part to here is supposed to be an example to allow the user to
guess at a number (7) with an infinite amount of tries.


This part was added as an exercise.
A counter is added to give 3 tries to guess the number.
It is supposed to stop after count gets to 3.  It doesn't.  It just
keeps looping back and asking for another guess.

>if count > 3:
>    print("That must have been complicated.")
>else:
>    print("Good job!")
>
>http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_3/Decisions
>
>Why not?
>I think I know why it isn't working, but I don't know enough yet on
>how it should work.
>The If statement isn't getting read.
--
https://mail.python.org/mailman/listinfo/python-list



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140807/4dbc18e2/attachment.html>


More information about the Python-list mailing list