[Tutor] Simple game

Tom Maher tomjmaher4 at gmail.com
Thu Mar 24 14:12:28 EDT 2016


Here is a simple game I am trying to create:


print "pick a number between 0 and 100 and tell me if it my guess is too
high (h) too low (l) or correct (c)"

guess = 0

print 'my guess is 50'

raw_input('your input ')

n = 50

while raw_input != 'c' or 'h' or 'l':

      if raw_input == 'h':

           guess += 1

           n -= (n/2)

      elif raw_input == "l":

           guess += 1

           n += (n/2)

      elif raw_input == 'c':

           print "It took " + str(guess) + "guesses"

           break

if raw_input is not 'c' or 'h' or 'l':

      print "please input either a c, h, or l"

elif print "game over"


I think its pretty obvious what I'm trying to do here - make a game that
will guess your number between 0 and 100 using a bisection search. I know I
made some embarrassingly obvious mistakes in the math up there but I can
worry about that later.  This is after a couple of attempts and so far my
code basically stops after the raw input prompt. No matter what I input it
doesn't respond. I originally tried to equate raw_input to x as a marker
but thought that maybe that changed the raw_input to be read AS x in the
code even after input. So instead I entered raw_input in every section to
represent the inputted value. Still stops at the prompt. Not sure if it is
something obvious or if it is something I'm oblivious to or what. Any help
is appreciated!


Thanks a lot,

Tom


More information about the Tutor mailing list