Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # A Guessing Game program that has the computer guess a number
- # between 1 and 100 using a binary search strategy.
- choice = 'y'
- while choice == 'y':
- low = 1
- high = 100
- print "Thinking of a number."
- input = raw_input("Press enter to continue. ")
- num = random.randint(1,100)
- guess = -1
- while guess!=num;
- guess = (low + high)/2
- print "\nThe computer guess is", guess
- if guess > num
- print "\nComputer guessed to high."
- high=guess
- elif guess < num
- print "\nComputer guessed to low."
- low=guess
- else
- print "\nComputer guess correctly!"
- choice = raw_input("Would you like to restart (y or n)? ")
- print "Exiting Program!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement