Guess the Number
2016-08-28 21:30
288 查看
问题:点击打开链接 (练习二):
注释文档:
1.程序询问是否想进行游戏:输入Yes
2.程序产生随机数value
3. 进入判断循环 , 输入数据guessNum 和 value产生对比,
if(guessNum > value) print 'too high';
elif(guessNum < value) print 'too low'
elif(guessNum == value) print 'correct'
发现相等时退出判断循环
# -*- coding: utf-8 -*-
import random
class Random(object):
def __init__(self, _min, _max):
self.min = _min
self.max = _max
def getValue(self):
return random.randint(self.min, self.max)
if __name__ == '__main__':
cnt = 0; flag = 0
ins = Random(0, 100) #取值范围为0-100
while True:
cnt = cnt+1
while True:
if cnt == 1:
print 'Would you like to roll \\ (Yes or No)'
else :
print 'Would you like to roll again \\ (Yes or No)'
str = raw_input()
if str == 'Yes':
break
elif str == 'No':
flag = 1
break
else:
print 'Illegal input'
if flag == 1:
break
value = ins.getValue()
while True:
guessNum = int(raw_input())
if guessNum == value:
print 'correct'
break
elif guessNum > value:
print 'too high'
elif guessNum < value:
print 'too low'
注释文档:
1.程序询问是否想进行游戏:输入Yes
2.程序产生随机数value
3. 进入判断循环 , 输入数据guessNum 和 value产生对比,
if(guessNum > value) print 'too high';
elif(guessNum < value) print 'too low'
elif(guessNum == value) print 'correct'
发现相等时退出判断循环
# -*- coding: utf-8 -*-
import random
class Random(object):
def __init__(self, _min, _max):
self.min = _min
self.max = _max
def getValue(self):
return random.randint(self.min, self.max)
if __name__ == '__main__':
cnt = 0; flag = 0
ins = Random(0, 100) #取值范围为0-100
while True:
cnt = cnt+1
while True:
if cnt == 1:
print 'Would you like to roll \\ (Yes or No)'
else :
print 'Would you like to roll again \\ (Yes or No)'
str = raw_input()
if str == 'Yes':
break
elif str == 'No':
flag = 1
break
else:
print 'Illegal input'
if flag == 1:
break
value = ins.getValue()
while True:
guessNum = int(raw_input())
if guessNum == value:
print 'correct'
break
elif guessNum > value:
print 'too high'
elif guessNum < value:
print 'too low'
相关文章推荐
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 2 Guess the number
- HDU 1562 Guess the number
- hdoj-1562-Guess the number
- IIPP迷你项目(二)"Guess the Number!"
- Guess the number
- 莱斯大学Python课程Mini-project # 2 - "Guess the number" game
- 杭电 HDU ACM 1562 Guess the number
- IIPP迷你项目(二)"Guess the Number!"
- guessTheNumber.py
- hdu 5981:Guess the number 动态规划
- 1562 Guess the number
- 作业week2 'Guess the number'
- game——Guess the number!
- “Guess the number” game
- 杭电OJ题 1562 Guess the number解题报告
- HDU 1562 Guess the number
- 2016 大连 K Guess the number HDU 5981 DP 打表找规律
- hdu-oj 1562 Guess the number
- HDU-5981-Guess the number-规律