小编plo*_*oms的帖子

类型错误:不可排序的类型:function() > int()

我不知道为什么在我的if statementsfor loops它认为它们是不可排序的类型来进行比较。我得到的确切错误如下:

Traceback (most recent call last):
  File "/Users/me/Documents/Eclipse/Week6/src/numbers.py", line 44, in <module>
    myDict = {'AvgPositive':posNumAvg(numInput), 'AvgNonPos':nonPosAvg(numInput),                'AvgAllNum':allNumAvg(numInput)}     
  File "/Users/me/Documents/Eclipse/Week6/src/numbers.py", line 30, in posNumAvg
    if num > 0:
TypeError: unorderable types: function() > int()
Run Code Online (Sandbox Code Playgroud)

我的代码如下:

#While loop function for user input
def numInput():
    numbers = []

    while True:
        num = int(input('Enter a number (-9999 to end):'))
        if num == -9999:
            break
        numbers.append(num)
    return numbers

#Average of all numbers function
def allNumAvg(numList):
    return sum(numList) / len(numList) …
Run Code Online (Sandbox Code Playgroud)

python pydev python-3.x

1
推荐指数
1
解决办法
9434
查看次数

python函数的返回值到底在哪里?

我的岩石剪刀代码不起作用,我假设它是因为我错误地使用了返回值.我该怎么办?

编辑,所以我存储了这样的回报

def results (x, y):
if (x == "R" or x == "rock" or x == "r" or x == "Rock" or x == "ROCK") and (y == "S" or y ==  "s" or y == "Scissors" or y == "SCISSORS" or y == "scissors"):
    winner = 1
    return winner
Run Code Online (Sandbox Code Playgroud)

但是如何在功能之外打印"胜利者"呢?

player1 = input ("Player 1: Please enter either Rock, Paper or Scissors:")

player2 = input ("Player 2: Please enter either Rock, Paper or Scissors:") 

def results (x, …
Run Code Online (Sandbox Code Playgroud)

python conditional return function

0
推荐指数
1
解决办法
665
查看次数

标签 统计

python ×2

conditional ×1

function ×1

pydev ×1

python-3.x ×1

return ×1