Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75833

RE: Wikibooks example doesn't work8

From Andrew Christianson <Andrew.Christianson@Ipsos.com>
Subject RE: Wikibooks example doesn't work8
Date 2014-08-07 03:43 +0000
References <r7s5u913pkc0ja59tko4ucravsliljkach@4ax.com>
Newsgroups comp.lang.python
Message-ID <mailman.12718.1407387878.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

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@python.org
Subject: Re: Wikibooks example doesn't work

On Wed, 06 Aug 2014 22:58:51 -0400, Seymore4Head
<Seymore4Head@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



Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Wikibooks example doesn't work Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-06 22:58 -0400
  Re: Wikibooks example doesn't work Chris Angelico <rosuav@gmail.com> - 2014-08-07 13:11 +1000
  Re: Wikibooks example doesn't work John Gordon <gordon@panix.com> - 2014-08-07 03:18 +0000
  Re: Wikibooks example doesn't work Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-06 23:25 -0400
    Re: Wikibooks example doesn't work Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-07 13:43 +1000
      Re: Wikibooks example doesn't work Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-06 23:48 -0400
        Re: Wikibooks example doesn't work Larry Hudson <orgnut@yahoo.com> - 2014-08-06 21:59 -0700
          Re: Wikibooks example doesn't work Ben Finney <ben+python@benfinney.id.au> - 2014-08-07 15:06 +1000
          Re: Wikibooks example doesn't work Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-07 11:11 -0400
    Re: Wikibooks example doesn't work alex23 <wuwei23@gmail.com> - 2014-08-07 14:09 +1000
    RE: Wikibooks example doesn't work8 Andrew Christianson <Andrew.Christianson@Ipsos.com> - 2014-08-07 03:43 +0000
  Re: Wikibooks example doesn't work Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-07 13:31 +1000

csiph-web