小编Nan*_*n N的帖子

不断收到 TypeError: 'int' 对象不可迭代

我不断收到此错误: TypeError: 'int' object is not iterable.

我需要做的作业(这样你对我想要实现的目标有一些背景)是这样的:“编写一个程序,创建 100 个随机整数,负数和正数都在 -10 和 +10 之间(在 for 循环中) ),然后确定有多少个是正数,有多少个是负数。最后,打印出有多少个数是正数,有多少个数是负数。”

import random

positive = 0
negative = 0

for number in random.randrange(-10,10):
    if number > 0:
        positive += 1
    else:
        negative += 1
print ("End")
Run Code Online (Sandbox Code Playgroud)

到目前为止,这是我的代码。如果有人可以帮助我使用上述信息和我的错误,那就太好了!

python int python-3.x

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

标签 统计

int ×1

python ×1

python-3.x ×1