Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. # A Guessing Game program that has the computer guess a number
  2. # between 1 and 100 using a binary search strategy.
  3.  
  4. choice = 'y'
  5.  
  6. while choice == 'y':
  7.  
  8.     low = 1
  9.     high = 100
  10.    
  11.     print "Thinking of a number."
  12.     input = raw_input("Press enter to continue. ")
  13.     num = random.randint(1,100)
  14.    
  15.     guess = -1
  16.    
  17.    
  18.     while guess!=num;
  19.         guess = (low + high)/2
  20.         print "\nThe computer guess is", guess
  21.        
  22.         if guess > num
  23.             print "\nComputer guessed to high."
  24.             high=guess
  25.         elif guess < num
  26.             print "\nComputer guessed to low."
  27.             low=guess
  28.         else
  29.             print "\nComputer guess correctly!"
  30.            
  31.    
  32.     choice = raw_input("Would you like to restart (y or n)? ")
  33.  
  34. print "Exiting Program!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement