i am trying the following code:
import simplegui
import random
import math
def new_game():
global secret_number
global low
global high
global n
print "New game. Range is from" ,low ,"-",high
secret_number=random.randrange(low,high)
n=math.ceil(math.log((high-low+1),2))
print "no of guesses",n
print " "
def new_game1():
global secret_number
print "New game. Range is from 0-100"
print " "
secret_number=random.randrange(0,100)
# define event handlers for control panel
def range100():
global low,high
low=0
high=100
new_game()
def range1000():
global low
global high
low=0
high=1000
new_game()
def input_guess(guess):
global secret_number
global n
g=int(guess)
print "Guess was",g
--n
print "no of guesses left",n
if(g>secret_number):
print "Lower"
elif(g<secret_number):
print "Higher"
else:
print "Equal"
frame = simplegui.create_frame('Testing', 200, 200)
button1 = frame.add_button('Range is(0,100)', range100,200)
button2 = frame.add_button('Range is(0,1000)', range1000,200)
inp = frame.add_input('Enter a guess', input_guess,200)
frame.start()
new_game1()
the problem with my above code is that I want to use a single newgame() fn which takes the default value of low as 0 and high as 100 . Right now I have bifurcated that function into newgame1() which is doing computations on the default values
How to rectify this problem? Please help