相关疑难解决方法(0)

Python - 不支持的类型:范围和范围

我试图运行脚本时遇到这个奇怪的错误,代码似乎是正确的但似乎python(3)不喜欢这部分:

        def function(x):
                  if integer:
                    return int(x)
                else:
                    return x

            non_nil = randrange(21)
            d = dict([(randrange(101), Racional(coeff(randrange(-20,20)),
                                    coeff(choice(range(-30,0)+\
                                                 range(1,30)))))
                     for k in range(non_nil)])
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

for k in range(non_nil)]) unsupported operand type(s) for +: 'range' and 'range'
Run Code Online (Sandbox Code Playgroud)

我已经尝试将最后四行放在一行中,但python返回相同的错误.

python range operand

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

带有 random.randint 的随机整数,没有特定数字

我正在尝试生成一个随机数。

import random
print(random.randint(1,10))
Run Code Online (Sandbox Code Playgroud)

我是否能够生成 1-10 之间的数字但不生成 x?

例如 x = 3

python

0
推荐指数
1
解决办法
187
查看次数

标签 统计

python ×2

operand ×1

range ×1