Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: unorderable types: int() > list()

# Import Packages
import random

# Global Variables
perf_num = 500
species = [20]
temp_num = 0
length = 0
s = 0

# Main Program
for num in range(100):
    r1 = int(random.random()*10)
    r2 = int(random.random()*10)
    species.append(r1)
    length = len(species)
    while s < length:
        print(s)
        if species[s-1] > species[s]:
            temp_num = species[s-1] - r1
            species[s-1] = temp_num
        else:
            temp_num = species[s] - r1
            species[s] = temp_num
        if s-1 < 5:
            species[s-1] = []
        s += 1

    print(species)

Please don't explain in very complicated coding language as I just started learning Python from youtube. I tried making my own program and continue to get this error.

like image 648
Vansh03 Avatar asked Jan 29 '26 02:01

Vansh03


1 Answers

In the following line:

species[s-1] = []

you're assigning an empty list to a list of numbers, which results in something like:

20 [20, 2] 2

Then when you try to compare a number and a list:

if species[s-1] > species[s]:

you'll get that error:

TypeError: unorderable types: int() > list()
like image 60
Nir Alfasi Avatar answered Jan 31 '26 18:01

Nir Alfasi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!