2 guess numbers



# template for "Guess the number" mini-project
# input will come from buttons and an input field
# all output for the game will be printed in the console
import simplegui
import random

times=7
num_range=100
# helper function to start and restart the game
def new_game():
    # initialize global variables used in your code here
    global secret_number 
    global n
    n=times
    secret_number = random.randrange(0, num_range)
    print "New game. Range is from 0 to "+str(num_range)
    print "Number of remaining guesses is "+str(n)
    print ""


# define event handlers for control panel
def range100():
    # button that changes the range to [0,100) and starts a new game 
    global num_range
    num_range=100
    global times
    times=7     
    new_game()  
      
def range1000():
    # button that changes the range to [0,1000) and starts a new game     
    global num_range
    num_range=1000  
    global times
    times=10 
    new_game()            
    
def input_guess(guess):
    # main game logic goes here	      
    global n
    n=n-1
    print "Guess was "+str(guess)
    print "Number of remaining guess is "+str(n)
    guess=int(guess)
    if secret_number>guess:
        print "Higer"
        print ""
        
    elif secret_number


你可能感兴趣的:(python,mini-projects,MOOC,python)