19 Jan 2015

Number Guessing game

#Python

'''
Number Guessing Game
'''



 

print "Please think of a number between 0 and 100!"
start=0
end=100
guess=50
while(1):
    print "Is your secret number",guess, "?"
    rd=raw_input("Enter 'h' to indicate the guess ls too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.")
    if(rd <>'c' and rd <>'l' and  rd<>'h'):
        print "Sorry, I did not understand your input."
    elif(rd=='c'):
        print "Game over. Your secret number was:", guess
        break
    elif(rd=='h'):
        end=guess
        guess=(start+end)/2
    else:
        start=guess
        guess=(start+end)/2   
   

Categories: , , ,

0 comments:

Post a Comment

Copyright © UPgradeCODING | Powered by Blogger