[Tutor] Help with Guess the number script
Scott Dunning
swdunning at me.com
Wed Mar 12 05:13:58 CET 2014
On Mar 11, 2014, at 1:57 AM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> OK so far, you don't need all the print statements
> but that's just a style issue. (You could just
> insert '\n' characters instead.)
You’re right, I’m actually not sure why I did it that way.
>
>> if guess < secret - 10 or guess > secret - 10:
>
> This is the right idea for cutting the line count but you
> have the comparison values wrong. Look back to earlier
> emails, you are repeating the same error as before.
> Manually think through what happens in the line above
> if guess == secret.
Oh, do you mean it should be <= and >=?? I’m not sure why that would work, because if guess==secret I have another statement in my code that takes care of that. I didn’t want to add my whole code because it’s too long but that is in there.
>
> And then once you get that fixed you can rewrite using
> the chained comparison trick to tidy it up.
> ie
> if not (lower limit < guess > upper limit):
I see what you’re saying about the chained comparison. What I’m having problems with is condensing it to half the lines of code so I don’t have to have the same conditionals under both ‘too low’ and ‘to high’. If that makes sense.
>
>
More information about the Tutor
mailing list