Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75821 > unrolled thread
| Started by | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| First post | 2014-08-06 22:58 -0400 |
| Last post | 2014-08-07 13:31 +1000 |
| Articles | 12 — 8 participants |
Back to article view | Back to comp.lang.python
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
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-08-06 22:58 -0400 |
| Subject | Wikibooks example doesn't work |
| Message-ID | <ilq5u9lfopj0g8227i5ko9s0lhn1ppcacm@4ax.com> |
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.")
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.
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-08-07 13:11 +1000 |
| Message-ID | <mailman.12717.1407381082.18130.python-list@python.org> |
| In reply to | #75821 |
On Thu, Aug 7, 2014 at 12:58 PM, Seymore4Head <Seymore4Head@hotmail.invalid> wrote: > 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. One thing you need to learn about Python... or, for that matter, pretty much any language. "It isn't working" is not very helpful; what you need to do is show what you expect and what it does. If the script throws an exception, post the full traceback. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2014-08-07 03:18 +0000 |
| Message-ID | <lrur6b$aog$1@reader1.panix.com> |
| In reply to | #75821 |
In <ilq5u9lfopj0g8227i5ko9s0lhn1ppcacm@4ax.com> Seymore4Head <Seymore4Head@Hotmail.invalid> writes:
> 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.")
>
> 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.
It would help tremendously if you gave us more detail than "it doesn't
work".
Do you get an error message?
Does the program not execute at all?
Does it execute, but give unexpected results?
--
John Gordon Imagine what it must be like for a real medical doctor to
gordon@panix.com watch 'House', or a real serial killer to watch 'Dexter'.
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-08-06 23:25 -0400 |
| Message-ID | <r7s5u913pkc0ja59tko4ucravsliljkach@4ax.com> |
| In reply to | #75821 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-08-07 13:43 +1000 |
| Message-ID | <53e2f5ed$0$29965$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #75825 |
Seymore4Head wrote:
> 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.
Ah, now things make sense! Your subject line is misleading! It's not that
the wikibooks example doesn't work, the example works fine. It's that the
code you added to it doesn't do what you expected. You should have said.
> 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.
You don't check the counter until after the loop has finished. It needs to
be inside the loop, not outside:
while looping:
# See the indent?
# this is inside the loop
# No indent.
# This is outside the loop.
Also, having reached the count of three, you will want to break out of the
loop. The "break" command does that.
Is this enough of a hint to continue? Please feel free to ask any further
questions you need.
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-08-06 23:48 -0400 |
| Message-ID | <7dt5u9pplvjpqvjegj39tes9ainr8ugsmi@4ax.com> |
| In reply to | #75829 |
On Thu, 07 Aug 2014 13:43:40 +1000, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
>Seymore4Head wrote:
>
>> 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.
>
>
>Ah, now things make sense! Your subject line is misleading! It's not that
>the wikibooks example doesn't work, the example works fine. It's that the
>code you added to it doesn't do what you expected. You should have said.
>
I copied it verbatim from the web page's solution. After indenting as
you suggested, it does work now though.
Thanks
>
>> 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.
>
>You don't check the counter until after the loop has finished. It needs to
>be inside the loop, not outside:
>
>while looping:
> # See the indent?
> # this is inside the loop
>
># No indent.
># This is outside the loop.
>
>
>Also, having reached the count of three, you will want to break out of the
>loop. The "break" command does that.
>
>Is this enough of a hint to continue? Please feel free to ask any further
>questions you need.
[toc] | [prev] | [next] | [standalone]
| From | Larry Hudson <orgnut@yahoo.com> |
|---|---|
| Date | 2014-08-06 21:59 -0700 |
| Message-ID | <HK-dnV8Kepg8mn7OnZ2dnUU7-emdnZ2d@giganews.com> |
| In reply to | #75830 |
On 08/06/2014 08:48 PM, Seymore4Head wrote:
> On Thu, 07 Aug 2014 13:43:40 +1000, Steven D'Aprano
> <steve+comp.lang.python@pearwood.info> wrote:
>
>> Seymore4Head wrote:
>>
>>> On Wed, 06 Aug 2014 22:58:51 -0400, Seymore4Head
>>> <Seymore4Head@Hotmail.invalid> wrote:
>>>
[snip]
>> Ah, now things make sense! Your subject line is misleading! It's not that
>> the wikibooks example doesn't work, the example works fine. It's that the
>> code you added to it doesn't do what you expected. You should have said.
>>
> I copied it verbatim from the web page's solution. After indenting as
> you suggested, it does work now though.
> Thanks
>
>>
>>> 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.
>>
I just took a look at that web page, and I see what your problem actually is...
You are misunderstanding the problem. The problem does NOT say to end the loop at three tries,
just to keep track of the number of tries. It's not actually specific, but the implication is
that AFTER the loop display a message depending on the number of actual tires.
The wikibooks solution IS correct, you understanding of the stated problem is not.
My response here may sound harsh but I don't mean it to be, so please don't take it that way.
Python is a great language to learn -- keep it up, you'll get it! :-)
-=- Larry -=-
[toc] | [prev] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2014-08-07 15:06 +1000 |
| Message-ID | <mailman.12719.1407388022.18130.python-list@python.org> |
| In reply to | #75832 |
Larry Hudson <orgnut@yahoo.com.dmarc.invalid> writes: > I just took a look at that web page, and I see what your problem > actually is... > You are misunderstanding the problem. The problem does NOT say to end > the loop at three tries, just to keep track of the number of tries. > It's not actually specific, but the implication is that AFTER the loop > display a message depending on the number of actual tires. Could it be re-phrased to state the exercise requirements more clearly? Maybe you could edit the wiki page to prevent future confusion on this exercise. -- \ “Are you pondering what I'm pondering?” “I think so, Brain, but | `\ wouldn't his movies be more suitable for children if he was | _o__) named Jean-Claude van Darn?” —_Pinky and The Brain_ | Ben Finney
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-08-07 11:11 -0400 |
| Message-ID | <6j57u99erojtibttpedh35053mgllmqdd0@4ax.com> |
| In reply to | #75832 |
On Wed, 06 Aug 2014 21:59:12 -0700, Larry Hudson <orgnut@yahoo.com> wrote: >On 08/06/2014 08:48 PM, Seymore4Head wrote: >> On Thu, 07 Aug 2014 13:43:40 +1000, Steven D'Aprano >> <steve+comp.lang.python@pearwood.info> wrote: >> >>> Seymore4Head wrote: >>> >>>> On Wed, 06 Aug 2014 22:58:51 -0400, Seymore4Head >>>> <Seymore4Head@Hotmail.invalid> wrote: >>>> > >[snip] >>> Ah, now things make sense! Your subject line is misleading! It's not that >>> the wikibooks example doesn't work, the example works fine. It's that the >>> code you added to it doesn't do what you expected. You should have said. >>> >> I copied it verbatim from the web page's solution. After indenting as >> you suggested, it does work now though. >> Thanks >> >>> >>>> 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. >>> > >I just took a look at that web page, and I see what your problem actually is... >You are misunderstanding the problem. The problem does NOT say to end the loop at three tries, >just to keep track of the number of tries. It's not actually specific, but the implication is >that AFTER the loop display a message depending on the number of actual tires. > >The wikibooks solution IS correct, you understanding of the stated problem is not. > >My response here may sound harsh but I don't mean it to be, so please don't take it that way. >Python is a great language to learn -- keep it up, you'll get it! :-) > > -=- Larry -=- It is OK. I have a thick skin. I also have a thick skull and need all the help I can get. Thanks
[toc] | [prev] | [next] | [standalone]
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Date | 2014-08-07 14:09 +1000 |
| Message-ID | <lruu5s$91m$1@dont-email.me> |
| In reply to | #75825 |
On 7/08/2014 1:25 PM, Seymore4Head wrote: > 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. You've misread the exercise: Modify the higher or lower program from this section to keep track of how many times the user has entered the wrong number. If it is more than 3 times, print "That must have been complicated." at the end, otherwise print "Good job!" There's nothing there about breaking out of the loop after 3 attempts, just producing a different end message on successful completion based on how many attempts were made. The Wikibooks example works as specified.
[toc] | [prev] | [next] | [standalone]
| From | Andrew Christianson <Andrew.Christianson@Ipsos.com> |
|---|---|
| Date | 2014-08-07 03:43 +0000 |
| Subject | RE: Wikibooks example doesn't work8 |
| Message-ID | <mailman.12718.1407387878.18130.python-list@python.org> |
| In reply to | #75825 |
[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
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-08-07 13:31 +1000 |
| Message-ID | <53e2f32a$0$29979$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #75821 |
Seymore4Head wrote: [snip code that looks fine to me] > Why not? I don't know. What does "doesn't work" mean? "It didn't do what I expected." (What did you expect? What did it do?) "It printed an error message." (Care to tell it what it was?) "It crashed the computer." (Some more details might help.) "My computer caught fire when I ran it." (I'm sorry to hear that.) Don't expect us to read your mind and know what you know. And don't expect us to run the code and see for ourselves -- we might, but we normally shouldn't need to, if you give as the details you already have. And of course just because it "doesn't work" on your system, doesn't mean it won't work on ours. -- Steven
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web