travisxuworld
2021-08-04 17:11
采纳率: 97%
浏览 92

python!我7位字母加上4位数字生成随机数组,要输出40000个,为什么就输出17000个,最后python结果就只有17190个,没有达到40000个,要如何操作可以达到40000个呢?


import random


def random1():
    headlist = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
                "V", "W", "X", "Y", "Z"]
    return  "".join(random.choice(headlist) for k in range(7)) \
           + "".join(random.choice("0123456789") for i in range(4))


def random2():
    headlist = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
                "V", "W", "X", "Y", "Z"]
    return  "".join(random.choice(headlist) for k in range(7)) \
           + "".join(random.choice("0123456789") for i in range(4))


for num in range(40000):
    print(random1())
  • 好问题 提建议
  • 收藏

1条回答 默认 最新

  • 八云黧 2021-08-04 17:15
    已采纳

    没啥问题,我执行你的代码直接跑到了40000个
    img

    已采纳该答案
    评论
    解决 无用
    打赏 举报