莱斯大学Python课程Mini-project # 2 - "Guess the number" game

要求:https://class.coursera.org/interactivepython-004/human_grading/view/courses/972072/assessments/29/submissions

我做的跟它的要求似乎有点不一样。中间遇到一个问题,费了好大力,发现是在文本框输入内容后没有按回车http://www.codeskulptor.org/

菜鸟一定要坚持下去!现在去吃晚饭

# interactive application to guess number
import random
import simplegui

# the globals
message = "now guess!"
high=100
low=0
target_number=random.randrange(low,high)
your_input=100

# compare the target number with your input
def compare_and_change():
   
   global message
    
   if target_number==your_input:
        message="correct,good job"
       
        
   elif target_numberyour_input:
        guessnow()
        message="your number is " +str(your_input)+" too small"
        
        
        
def guessnow():
    input_handler
    compare_and_change


#define draw handler
def draw(canvas):
    canvas.draw_text(message,[10,150],16,"White")


# define an input field handler
def input_handler(text):
    global your_input
    global message
    your_input=float(text)
    message=str(your_input)
    if your_inputhigh:
         message= "your num is out of range,try again" 
 

    
#creat frame
frame=simplegui.create_frame("Guess",300,200)

#registor event handler
frame.set_draw_handler(draw)
frame.add_input("guess a number,then press enter",input_handler,180)
frame.add_button("compare",compare_and_change,100)  

#start
frame.start()



你可能感兴趣的:(练习都是黑历史)