双色球选购小程序
从红球里取6个球,范围是1-33;蓝色球里取1个球,范围是1-16。
重复循环,就很low
red_balls = []
blue_balls = []
count = 0
while count < 6:
choice = input(f'输入第{i}个红球>:').strip()
if not choice.isdigit():
print('不合法')
continue
choice = int(choice)
if 0 < choice < 33 and choice not in red_balls:
red_balls.append(choice)
count += 1
#蓝求重复
进阶版
red_balls = []
blue_balls = []
li = [[6,33,'红球',red_balls],[1,16,'篮球',blue_balls]]
for item in li:
print(item)
print(f'开始选择{item[2]}'.center(50,'-'))
count = 0
while count < item[0]:
choice = input(f'选择第{count}个{item[2]}>>:').strip()
if not choice.isdigit():
print('不合法')
continue
choice = int(choice)
if 0 < choice < item[1] and choice not in item[3]:
item[3].append(choice)
count += 1
print(red_balls)
print(blue_balls)