2 guess numbers
来源:互联网 发布:world of goo mac 编辑:程序博客网 时间:2024/06/03 02:50
# 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 consoleimport simpleguiimport randomtimes=7num_range=100# helper function to start and restart the gamedef new_game(): # initialize global variables used in your code here global secret_number global n n=times secret_number = random.randrange(0, num_range) print "New game. Range is from 0 to "+str(num_range) print "Number of remaining guesses is "+str(n) print ""# define event handlers for control paneldef range100(): # button that changes the range to [0,100) and starts a new game global num_range num_range=100 global times times=7 new_game() def range1000(): # button that changes the range to [0,1000) and starts a new game global num_range num_range=1000 global times times=10 new_game() def input_guess(guess): # main game logic goes here global n n=n-1 print "Guess was "+str(guess) print "Number of remaining guess is "+str(n) guess=int(guess) if secret_number>guess: print "Higer" print "" elif secret_number<guess: print "Lower" print "" else: print "Correct" print "" new_game() if n==0: print "You ran out of guesses. The number was "+str(secret_number) # create frameframe = simplegui.create_frame('Guess the number',300,300)inp = frame.add_input('Enter a guess', input_guess, 50)# register event handlers for control elements and start frameframe.add_button("Range: 0 - 100", range100, 100)frame.add_button("Range: 0 - 1000", range1000, 100)# call new_game new_game()# always remember to check your completed program against the grading rubric
0 0
- 2 guess numbers
- HDU 4192 Guess the Numbers (表达式)
- HDU-4192 Guess the Numbers 表达式求值
- Guess
- guess
- POJ-4039(编译原理)(Guess the Numbers)
- UVA12392/HDU4192 Guess the Numbers 枚举+逆波兰
- HDU-4192 Guess the Numbers 中缀转后缀
- HDU 4192 Guess the Numbers 栈的应用
- HDOJ-4192-Guess the Numbers【用栈实现计算器】
- Mini-project # 2 - "Guess the number" game"
- Guess(精确2位浮点数)
- Codeforces Round #241 (Div. 2) A. Guess a number!
- 【codeforces】 Round #287 (Div. 2) C. Guess Your Way Out!
- Codeforces Round #287 (Div. 2) C. Guess Your Way Out!
- Codeforces Round #287 (Div. 2) C. Guess Your Way Out!
- Codeforces Round #287 (Div. 2) C. Guess Your Way Out!
- Codeforces Round #287 (Div. 2)C. Guess Your Way Out!
- 【算法】_015_矩阵乘法_直接递归
- fileupload乱码问题.
- getContextPath、getServletPath、getRequestURI的区别
- java斜杠展开的联想
- 【算法】_016_矩阵乘法_Strassen算法
- 2 guess numbers
- 开发fileupload组件的专属操作类
- Css中Position属性的含义
- tomcat自动加载问题
- servlet客户端跳转+服务器端跳转
- 前言
- Ubuntu12.0.4安装nagios3.2.3中文
- HDU 4821 String 字符串hash map的妙用
- servlet过滤器的链式处理