小编Har*_*ton的帖子

Python - AttributeError: 'int' 对象没有属性 'randint'

作为 python 课程的一部分,我正在做的任务之一是生成 1 到 10 100,000 次之间的随机数,并计算每个数字出现的次数。这是我为此任务编写的代码:

    import random

    one = 0
    two = 0
    three = 0
    four = 0
    five = 0
    six = 0
    seven = 0
    eight = 0
    nine = 0
    ten = 0
    count = 0

    while count < 100000:
        random = random.randint(1, 10)

        if random == 1:
            one += 1
        elif random == 2:
            two += 1
        elif random == 3:
            three += 1
        elif random == 4:
            four += 1
        elif …
Run Code Online (Sandbox Code Playgroud)

random attributeerror python-3.x

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

attributeerror ×1

python-3.x ×1

random ×1