TypeError:“>" 'list'和'int'的实例之间不支持 [英] TypeError: '>' not supported between instances of 'list' and 'int'
问题描述
我正在研究一个用于计算游戏中某些值的库.我有以下代码:
I'm working on a library for calculating certain values in a game. I have this code:
million = [1000000, "M"]
billion = [million * 1000, "B"]
trillion = [billion * 1000, "T"]
quadrillion = [trillion * 1000, "Qd"]
quintillion = [quadrillion * 1000, "Qn"]
sx = [quintillion * 1000, "Sx"]
septillion = [sx * 1000, "Sp"]
suffixes = [million, billion, trillion, quadrillion, quintillion, sx, septillion]
def getSetupResult(orevalue, furnacemultiplier, *upgrades, **kwargs):
for i in upgrades:
orevalue *= i
orevalue *= furnacemultiplier
for suffix in suffixes:
if orevalue > suffix[0] - 1 and orevalue < suffix[0] * 1000:
print("$"+str(orevalue)+suffix[1])
getSetupResult(quintillion,700,5,4,10,100)
当我尝试运行它时,会引发此错误:
When I try to run it, it raises this error:
Traceback (most recent call last):
File "C:/Users/???/Desktop/MinersHavenCalculator.py", line 19, in <module>
getSetupResult(quintillion,700,5,4,10,100)
File "C:/Users/???/Desktop/MinersHavenCalculator.py", line 16, in getSetupResult
if orevalue > suffix[0] - 1 and orevalue < suffix[0] * 1000:
TypeError: '>' not supported between instances of 'list' and 'int'
是什么原因导致此错误?
What's causing this error?
推荐答案
您有很多问题,无法区分列表和整数.
You have a lot of issues where you don't distinguish between lists and integers.
million = [1000000, "M"]
billion = [million * 1000, "B"]
billion[0]
实际上不是1000000 * 1000
,它是长度为1000的列表.
billion[0]
is not actually a 1000000 * 1000
, its a length 1000 list.
这是所有问题的根源,因为现在suffix[0]
成为循环中第一次迭代后的列表.您需要进行的最大更改如下:
This is the root of all your problems, since now suffix[0]
becomes a list after the first iteration through your loop. The biggest change you needed was as follows:
million = [1000000, "M"]
billion = [million[0] * 1000, "B"]
trillion = [billion[0] * 1000, "T"]
quadrillion = [trillion[0] * 1000, "Qd"]
quintillion = [quadrillion[0] * 1000, "Qn"]
sx = [quintillion[0] * 1000, "Sx"]
septillion = [sx[0] * 1000, "Sp"]
这确保了每个都是具有适当后缀和值的两个元素列表.这是全部:
This makes sure that each of these is a two element list with the proper suffix and value. Here it is all together:
suffixes = [million, billion, trillion, quadrillion, quintillion, sx, septillion]
def getSetupResult(orevalue, furnacemultiplier, *upgrades, **kwargs):
for i in upgrades:
orevalue *= i
orevalue *= furnacemultiplier
for suffix in suffixes:
if orevalue > suffix[0] - 1 and orevalue < suffix[0] * 1000:
print("$"+str(orevalue)+suffix[1])
getSetupResult(quintillion[0],700,5,4,10,100)
输出:
$14000000000000000000000000Sp
这篇关于TypeError:“>" 'list'和'int'的实例之间不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!