Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. # template for "Guess the number" mini-project
  2. # input will come from buttons and an input field
  3. # all output for the game will be printed in the console
  4.  
  5. import simplegui
  6. import random
  7.  
  8. secret_number = random.randint(0,100)
  9.  
  10. # helper function to start and restart the game
  11. def new_game():
  12. global secret_number
  13. secret_number = random.randint(0,100)
  14.  
  15.  
  16. # initialize global variables used in your code here
  17.  
  18. # remove this when you add your code
  19. pass
  20.  
  21.  
  22. # define event handlers for control panel
  23. def range100():
  24. # button that changes the range to [0,100) and starts a new game
  25.  
  26. # remove this when you add your code
  27. pass
  28.  
  29. def range1000():
  30. # button that changes the range to [0,1000) and starts a new game
  31.  
  32. pass
  33.  
  34. def input_guess(guess):
  35. int(guess)
  36. if secret_number>guess:
  37. print "Guess was " + guess + ". Higher"
  38. elif secret_number==guess:
  39. print "Guess was " + guess + ". Correct"
  40. else:
  41. print "Guess was " + guess + ". Lower"
  42. # main game logic goes here
  43.  
  44.  
  45.  
  46. # create frame
  47. frame = simplegui.create_frame("w/e", 200, 200)
  48. frame.add_input("Enter guess here", input_guess, 100)
  49.  
  50. # register event handlers for control elements and start frame
  51. frame.start()
  52.  
  53. # call new_game
  54. new_game()
  55.  
  56.  
  57. # always remember to check your completed program against the grading rubric
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement