1 Replies - 2897 Views - Last Post: 14 January 2012 - 05:47 PM Rate Topic: -----

#1 emrah.dgd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-January 12

Reverse Python Guessing game

Posted 13 January 2012 - 08:29 PM

I keep trying to reverse the python guessing game. I am trying to get python to guess my number. I can't seem to do it, could someone help me with this.

high = 11

low = 1

print "welcome to the game"

print " enter username "

username = raw_input()

print "hello" " " + username

print " i will try to guess your number, think of a number between 1 and 10"


guess = (high-low)/2


print "please enter your number"

number = raw_input()

while guess != number:
    if number > guess:
        low == guess
    elif number < guess:
        high == guess
    else:
        print ' your number is ' + str(guess)
    guess == (high-low)/2

This post has been edited by Simown: 15 January 2012 - 06:02 AM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Reverse Python Guessing game

#2 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: Reverse Python Guessing game

Posted 14 January 2012 - 05:47 PM

I won't solve your problem for you, but I think I can head you in the right direction.
*Please use code tags in the future around your code as especially with Python tabbing is crucial to logic.

1) Your == in your while loop should be =
2) your guess value is often a float and will never equal an int. Ex:
high=5,low=2 guess=(5-2)/2 = 1.5 which won't match any integer input.
3) If I was to enter 5 as my number I would never get into the while loop and the program would end.
4) I think 0 is technically your low or 10 is your high, but one of them should change.

Try those out to start and see if you can correct your logic. Post back if you're still having issues :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1