python不支持的类型_Python-不支持的类型:范围和范围

1586010002-jmsa.png

I'm getting this strange error trying to run a script, the code appears to be correct but it seems python (3) didn't liked this part:

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)])

And i get the following error:

for k in range(non_nil)]) unsupported operand type(s) for +: 'range' and 'range'

I already tried to put the last four lines in a single one but python returns the same error.

解决方案

This is because Python 3 range does not return a list, like Python 2. This code was written for Python 2.

This code, should be changed:

range(-30,0) + range(1,30)

It should be changed to:

list(range(-30,0)) + list(range(1,30))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值