Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

python - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have a lot of issues where you don't distinguish between lists and integers.

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

billion[0] is not actually a 1000000 * 1000, its a length 1000 list.

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)

Output:

$14000000000000000000000000Sp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...