如何避免在'tuple'和'int'的实例之间不支持TypeError:'>'?

时间:2020-05-03 00:12:56

标签: python python-3.x typeerror

我正在创建一个模拟Nba球员状态的程序。我是一个初学者,很不幸,我遇到了以下错误:

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

此错误发生在数字> 0:

到目前为止,这是我的代码:

import random

Malcolm_Brogdon_tendencies = { "Under_Basket_Rate" : 396, 
"Close_Left_Rate" : 32, "Close_Mid_Rate" : 50, "Close_Right_Rate" : 38, "Mid_Left_Rate" : 6, "Mid_Mleft_Rate" : 36, "Mid_Mleft" : 375, "Mid_Mid_Rate" : 47, 
"Mid_Mright_Rate" : 83, "Mid_Right_Rate" : 15, "Three_Left_Rate" : 8, "Three_Mleft_Rate" : 91, "Three_Mid_Rate" : 70, "Three_Mright_Rate" : 109, "Three_right_Rate" : 18}

Malcolm_Brogdon_Percentages = {"Under_Basket" : 487, "Close_Left" : 571, "Close_Mid" : 515, "Close_Right" : 480, "Mid_Left" : 500, "Mid_Mleft" : 375,
 "Mid_Mid" : 452, "Mid_Mright" : 564, "Mid_Right" : 400, "Three_Left" : 0, "Three_Mleft" : 350, "Three_Mid" : 261, "Three_Mright" : 319, "Three_Right" : 417}

Malcolm_Brogdon_Person = {"Shot_Attempts" : random.randint(10,16)}

do_not_include = [0]
total_shots = 0


while total_shots< Malcolm_Brogdon_Person["Shot_Attempts"]: 
    for tendencies, numbers in Malcolm_Brogdon_tendencies.items(): 
        for numbers in Malcolm_Brogdon_tendencies.items(): 
            while numbers > 0: 
                shot_distribution = random.randint(1,1001) 
                if shot_distribution not in do_not_include: 
                    do_not_include.append(shot_distribution) 
                    total_shots = total_shots + 1 
                    numbers = numbers - 1 

            
            
print (do_not_include)

我也理解从互联网上导入数据会更容易,但是,我想开始慢一点。数字代表每1000次发生的次数。然后,对于Malcolm_Brogdon_Tendencies中的每个数字,它将生成1000个数字中的许多数字,并为其分配一个值,使得Close_Left_Rate例如发生32/1000次。可能有一种更简单的方法来执行此操作,但是,我是编程新手,并不了解那么多。

我知道变量数字是Malcolm_Brogdon_Tendencies中的值,因此不能与int进行比较。有没有一种方法可以解析数字,使其成为一个整数?

感谢所有提供帮助的人,因为我意识到我给出了一个可怕的描述,并且我的代码可能会大量简化。

2 个答案:

答案 0 :(得分:0)

可能您正在尝试访问项中(键,值)对的数字部分,因此请尝试替换

while numbers > 0: 

使用

while numbers[1] > 0:

答案 1 :(得分:-1)

尝试更换

while numbers > 0: 

使用

while int(numbers[0]) > 0:

这样,它将只比较元组中的整数。