gpt4 book ai didi

python - 类型错误 : '>' not supported between instances of 'list' and 'int'

转载 作者:行者123 更新时间:2023-12-05 09:16:55 25 4
gpt4 key购买 nike

我正在开发一个用于计算游戏中某些值的库。我有这段代码:

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)

当我尝试运行它时,它引发了这个错误:

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'

是什么导致了这个错误?

最佳答案

你有很多问题是你不区分列表和整数。

million = [1000000, "M"]
billion = [million * 1000, "B"]

billion[0] 实际上不是 1000000 * 1000,它是一个长度为 1000 的列表。

这是所有问题的根源,因为现在 suffix[0] 在循环的第一次迭代后变成了一个列表。您需要做的最大改变如下:

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

这确保其中的每一个都是具有正确后缀和值的二元素列表。这一切都在这里:

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

关于python - 类型错误 : '>' not supported between instances of 'list' and 'int' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49472108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com