[Python] 纯文本查看 复制代码 import random as rd
def num(s):
while True:
try:
i = int(input(s))
if i< 0:
print('请重新输入一个正整数。')
continue
else:
break
except ValueError:
print('请重新输入一个正整数。')
continue
return i
sum_num = num('请输入抽奖池数量:')
luck_num = 0
round_num = num('请输入抽奖次数:')
while True:
if round_num > sum_num - luck_num:
print('中奖次数不合理,请重新输入抽奖次数。')
round_num = num('请输入抽奖次数:')
continue
else:
break
i = 0
lucks =[]
while i < round_num:
round_luck = []
j = 0
luck_num = num('请输入中奖人数:')
while True:
if luck_num > sum_num - len(lucks):
print(f'还剩{sum_num - len(lucks)}没有中奖,请重新输入中奖人数。')
luck_num = num('请输入中奖人数:')
continue
else:
break
while j < luck_num:
temp = rd.choice(range(1,sum_num+1))
if temp in lucks:
print(temp,'重复了!')
continue
else:
lucks.append(temp)
round_luck.append(temp)
print(f'第{j+1}个中奖者是',':',temp)
j += 1
print(f'第{i+1}次中奖者{len(round_luck)}位是:',round_luck)
i += 1
unlucks = []
for k in range(1,sum_num+1):
if k not in lucks:
unlucks.append(k)
unlucks.sort()
lucks.sort()
print(f'得奖人数是{len(lucks)},分别为:',lucks)
print(f'没有得奖人数是{len(unlucks)},分别为:',unlucks) |