写一个抽奖游戏,比如中奖号码为55,键盘输入你抽奖的数字,进行抽奖

def draw_prize():
import random
prize = ['iphone', '华为', '相机', 'computer', '8000现金']
data = list(range(100))
random_num = random.choice(data)
while True:
try:
num = int(input('请输入一个正整数:').strip())
max_num = max(data)
min_num = min(data)
if num >= min_num and num <= max_num:
if num == random_num:
print('恭喜您,抽奖成功,抽到的奖品是:%s' % random.choice(prize))
break
elif num < random_num:
print('您输入的数字小了,请重新输入!')
else:
print('您输入的数字大了,请重新输入!')
else:
print('您输入的数字超过了范围,请重新输入!')

except Exception as e:
print('错误是:%s' % e)


draw_prize()
原文地址:https://www.cnblogs.com/laosun0204/p/11127709.html