-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuess the number
87 lines (69 loc) · 1.92 KB
/
Guess the number
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Testing template for "Guess the number"
###################################################
# input will come from buttons and an input field
# all output for the game will be printed in the console
import simplegui
import random
import math
secret_number = 0
lower_limit = 0
higher_limit = 100
number = 7
choose_num = 1
def new_game():
global secret_number
secret_number = random.randrange(lower_limit,higher_limit + 1)
if choose_num == 1:
button1()
else:
button2()
def button1():
global choose_num
global lower_limit
global higher_limit
global number
choose_num = 1
number = 7
lower_limit = 0
higher_limit = 100
print ""
print "New game. Range is from 0 to 100"
print "Number of remaining guesses is 7"
def button2():
global choose_num
global lower_limit
global higher_limit
global number
choose_num = 2
number = 10
lower_limit = 0
higher_limit = 1000
print ""
print "New game. Range is from 0 to 1000"
print "Number of remaining guesses is 10"
def input_guess(guess):
global number
guess = int(guess)
number = number -1
print ""
print "Guess was",guess
print "Number of remaining guesses is",number
if guess > higher_limit or guess < lower_limit:
print "Invalid guess"
new_game()
if guess == secret_number:
print "Correct!"
new_game()
elif guess < secret_number:
print "Higher!"
elif guess > secret_number:
print "Lower!"
if number ==0:
print "You ran out of guesses. The number was",secret_number
new_game()
frame = simplegui.create_frame("Guess the number",200,200)
button100 = frame.add_button("Range 0 - 100",button1)
button1000 = frame.add_button("Range 0 - 1000",button2)
inp = frame.add_input("Enter the Guess",input_guess,50)
frame.start()
new_game()