def draw_prize():
import random
prizes = ['iphone', '华为手机', '相机', 'computer', '8000现金']
data = list(range(100))
random_data = random.choice(data)
while True:
try:
input_data = input('请输入一个数字:').strip()
max_data = max(data)
min_data = min(data)
if input_data != '':
if int(input_data) >= min_data and int(input_data) <= max_data:
if int(input_data) == random_data:
print('恭喜您,抽奖成功,抽到的奖品是:%s' % random.choice(prizes))
break
elif int(input_data) < random_data:
print('小了,小了,请重新输入!')
else:
print('大了,大了,请重新输入!')
else:
print('超出范围,请重新输入!')
else:
print('输入不允许为空')
except Exception as e:
print('内容格式错误,重新输入,错误是:%s' % e)
draw_prize()