Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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
- secret_number = random.randint(0,100)
- # helper function to start and restart the game
- def new_game():
- global secret_number
- secret_number = random.randint(0,100)
- # initialize global variables used in your code here
- # remove this when you add your code
- pass
- # define event handlers for control panel
- def range100():
- # button that changes the range to [0,100) and starts a new game
- # remove this when you add your code
- pass
- def range1000():
- # button that changes the range to [0,1000) and starts a new game
- pass
- def input_guess(guess):
- int(guess)
- if secret_number>guess:
- print "Guess was " + guess + ". Higher"
- elif secret_number==guess:
- print "Guess was " + guess + ". Correct"
- else:
- print "Guess was " + guess + ". Lower"
- # main game logic goes here
- # create frame
- frame = simplegui.create_frame("w/e", 200, 200)
- frame.add_input("Enter guess here", input_guess, 100)
- # register event handlers for control elements and start frame
- frame.start()
- # call new_game
- new_game()
- # always remember to check your completed program against the grading rubric
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement