red_balls=[]
blue_balls=[]
zx=[[6,33,"红球",red_balls],[1,16,"蓝球",blue_balls]]
for item in zx:
print(f"开始选择{item[2].center(50,'-')}")
count=0
while count<item[0]:
choice=input(f"输入第{count+1}个{item[2]}:")
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,blue_balls)
运行结果如下:

文章详细描述了一个Python脚本,用户可以通过交互方式选择红球和蓝球,程序实现动态添加球至对应列表。
&spm=1001.2101.3001.5002&articleId=135393390&d=1&t=3&u=f4493562395e48ac984aee182319e1fe)

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



