red_balls = []
blue_balls = []
count = 0
while count < 6:
choice = input(f"输入第{count + 1}个红球:")
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
count = 0
while count < 1:
choice = input(f"输入第{count + 1}个蓝球:")
if not choice.isdigit():
print("不合法")
continue
choice = int(choice)
if 0 < choice <= 16 and choice not in blue_balls:
blue_balls.append(choice)
count += 1
print(red_balls, blue_balls)
运行结果如下:

这篇文章展示了如何使用Python编写一个简单的控制台程序,用户依次输入红球和蓝球的编号,程序检查输入的合法性并将它们添加到对应的列表中。

3549

被折叠的 条评论
为什么被折叠?



