On 03/07/2014 06:30 AM, Scott W Dunning wrote:
I am trying to write a script for class for a game called guess the number.
I’m almost done but, I’m having a hard time getting the hints to print
correctly. I’ve tried ‘if’’ ‘elif’ nested, it seems like everything….I’m
posting my code for the hints below, any help is greatly appreciated!
def print_hints(secret, guess):
if guess < 1 or guess > 101:
print
print "Out of range!"
print
if guess < secret:
print
print "Too low!"
elif guess < (secret - 10) or guess > (secret - 10):
print "You are cold!"
print
print "Please play again!"
elif guess < (secret - 5) or guess > (secret - 5):
print "You are warmer!"
print
else:
print "You're on fire!!"
if guess > secret:
print
print "Too high!"
print
elif guess < (secret - 10) or guess > (secret - 10):
print "You are cold!"
print
elif guess < (secret - 5)or guess > (secret - 5):
print "You are warmer!"
print
print "Please play again!"
else:
print "You're on fire!!"
Thanks again!!
Scott
You are providing 3 kinds of hints to the player, and trying to mix 2 of them
_cleverly_ in code, which leads to confusion. Much more clever in fact, in 99%
cases, not to try to clever, because programming is difficult enough;
programming provides us with high challenges to your limited mind, whether or
not we add to the difficulty with supposed clever tricks.
clever programming is stupid
stupid programming is clever
The three kinds of hints are:
* whether or not the guess is in interval; this must be done first, and apart,
which you do well; but when it is not the case, you can quit the function
immediately: the other tests & honts make no sense; right? challenge: update
your design so that the program tells whether the guess is in _present_
interval, instead of the _initial_ one
* too high, too low, or found (and "on fire"); in the latter case, you can quit
the function
* whether "cold", "warmer", or in-between; this only makes sense if guess is in
interval, and not found; note that in fact depends on the _absolute_ difference
Another logic is to reverse the last two hints: first deal with the
"temperature" hints, including "on fire"; then only say high/low, when in
interval and not found / not "on fire". I guess this more corresponds to what
you were trying to express.
d
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor