点击查看代码
import random
# 双色球
# 红球6个,1-33之间的整数,不重复
# 蓝球1个,1-16之间的整数,
# 1、随机产生一个列表,6个红球,1个蓝球
# list1 = []
#
# while len(list1) < 6:
# n1 = random.randint(1, 33)
# if n1 not in list1:
# list1.append(n1)
# n2 = random.randint(1, 16)
# list1.append(n2)
# print(list1)
# 2、在控制台中买一注彩票,
# 提示:请输入第一个红球,号码不在范围内,号码重复,都要重新输入
list2 = []
while len(list2) < 6:
n3 = int(input(f'请输入第{len(list2) + 1}个红球:'))
if n3 not in list2 and 1 <= n3 <= 33:
list2.append(n3)
else:
print('号码不在范围内,或者号码重复,都要重新输入')
while len(list2) < 7:
n4 = int(input(f'请输入蓝球:'))
if 1 <= n4 <= 16:
list2.append(n4)
else:
print('号码不在范围内,要重新输入')
print(list2)