Help with the Guess mu number,
Hi All,
Thanks for yours comments.
Alan's comment has helped me to resolve this situation.
Removing the indentaion was the solution.
Thanks
Ofir
Send Tutor mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
https://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."
Today's Topics:
1. Help with guess my number game (????? ?????)
2. Re: Help with guess my number game (Danny Yoo)
3. Fwd: Re: Help with guess my number game (Danny Yoo)
4. Re: Help with guess my number game (Alan Gauld)
----------------------------------------------------------------------
Message: 1
Date: Mon, 13 Oct 2014 13:40:45 +0300
From: ????? ?????
To:
Subject: [Tutor] Help with guess my number game
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
An HTML attachment was scrubbed...
URL:
------------------------------
Message: 2
Date: Mon, 13 Oct 2014 13:06:26 -0700
From: Danny Yoo
To: ????? ?????
Cc: Python Tutor Mailing List
Subject: Re: [Tutor] Help with guess my number game
Message-ID:
Content-Type: text/plain; charset=UTF-8
>
> if guess != the_number:
>
> print ("you failed, the number was", the_number)
>
> elif guess==the_number:
>
> print("You guessed it! The number was", the_number)
>
> print("And it only took you", tries, "tries!n")
This block of code appears to be applied for every iteration through
your loop. Is that your intention?
------------------------------
Message: 3
Date: Mon, 13 Oct 2014 13:43:10 -0700
From: Danny Yoo
To: Python Tutor Mailing List
Subject: [Tutor] Fwd: Re: Help with guess my number game
Message-ID:
Content-Type: text/plain; charset=UTF-8
---------- Forwarded message ----------
From: ????? ?????
Date: Mon, Oct 13, 2014 at 1:20 PM
Subject: Re: Re: [Tutor] Help with guess my number game
To: Danny Yoo
Hi Danny
Thanks for your response,
I think it is part of the problem, but my intention was to end the
first loop only after 5 tries.
I don't understand why the code go to the print section after only two
gusses and not five. and it also reveal the_number before the game
end.
Again thank for your help.
Ofir
________________________________
????: Danny Yoo,
????: Re: [Tutor] Help with guess my number game
>
> if guess != the_number:
>
> print ("you failed, the number was", the_number)
>
> elif guess==the_number:
>
> print("You guessed it! The number was", the_number)
>
> print("And it only took you", tries, "tries!n")
This block of code appears to be applied for every iteration through
your loop. Is that your intention?
________________________________
Walla! Mail - Get your free unlimited mail today
------------------------------
Message: 4
Date: Tue, 14 Oct 2014 00:39:00 +0100
From: Alan Gauld
To: [email protected]
Subject: Re: [Tutor] Help with guess my number game
Message-ID:
Content-Type: text/plain; charset=UTF-8; format=flowed
On 13/10/14 11:40, ????? ????? wrote:
> # set the initial values
>
> the_number = random.randint(1, 100)
> guess = int(input("Take a guess: "))
> tries = 1
>
> # guessing loop
> while guess != the_number:
> if guess > the_number:
> print("Lower...")
> else:
> print("Higher...")
> guess = int(input("Take a guess: "))
>
> tries += 1
> if tries > 5:
> break
so far so good....
almost...
>
> if guess != the_number:
> print ("you failed, the number was", the_number)
This is still inside the loop. You want to remove the
indentation so this only happens after you exit the loop.
Otherwise you tell the user the answer before they guess
it (or have 5 goes) and it doesn't work right if the
first guess is correct...
> input("nnPress the enter key to exit.")
You need the if/else to look like this.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
------------------------------
Subject: Digest Footer
_______________________________________________
Tutor maillist - [email protected]
https://mail.python.org/mailman/listinfo/tutor
------------------------------
End of Tutor Digest, Vol 128, Issue 33
**************************************