#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'huhu, <huyoo353@126.com>'
def find_middle(start, end):
#print start, end
return round((start+end)/2.0)
if __name__ == '__main__':
start, end = '',''
text = raw_input(u"> 输入猜数的范围(如:421-499 或者421 499 或者421,499):").decode('gb18030')
spliters = '-, '
for c in spliters:
if text.find(c) != -1:
num_list = text.split(c)
if ''.join(num_list).isdigit():
start, end = num_list[0],num_list[1]
break
if start == '' or end == '':
print u'范围不正确'
else:
start = int(start)
end = int(end)
count = 1
last_guess = find_middle(start,end)
while 1:
result = raw_input(u"放弃猜测直接回车, 等于输入=, 小了输入1, 大了请输入2\n>>> #猜数[%d] ,对吗?> " % last_guess ).decode('gb18030')
#print type(text)
if result in ['q','e','exit','quit','bye',u'退出']:
print 'Bye!'
break
else:
result=result.strip()
if result == '1':
start = last_guess
last_guess = find_middle(last_guess,end)
elif result == '2':
end = last_guess
last_guess = find_middle(start,last_guess)
elif result == '=':
print u'恭喜猜中, 共猜了%d次' % count
print u'#猜数[%d]' % last_guess
break
else: #
continue
count += 1
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有