Having Trouble With: Tuple and Int?

后端 未结 1 935
耶瑟儿~
耶瑟儿~ 2021-01-28 20:02

So I am making a camel game and I get a weird error that says

\"TypeError: \'>\' not supported between instances of \'tuple\' and \'int\'\"

相关标签:
1条回答
  • 2021-01-28 20:50

    You need to take the number out of the tuple and into a variable that is also an integer.

    There are multiple integers in your tuple.

    You can access them in the following way:

    some_tuple_of_integers = (12, 432, 345)
    
    index_zero_integer = some_tuple_of_integers[0]
    index_one_integer = some_tuple_of_integers[1]
    index_two_integer = some_tuple_of_integers[2]
    
    print(index_zero_integer)
    print(index_one_integer)
    print(index_two_integer)
    

    Or just straight from the tuple itself without creating a new variable (This can sometimes get unreadable when working with lots of indexes and tuples).

    print(some_tuple_of_integers[0])
    print(some_tuple_of_integers[1])
    print(some_tuple_of_integers[2])
    

    You can then easily compare between other values.

    If, for example you have a string from the tuple that you need to compare with another integer, you can change it by doing:

    index_two_integer = int(index_two_integer)
    
    0 讨论(0)
提交回复
热议问题