2016-11-02 48 views
-1

我試圖把我的代碼更新mostComp每次的值檢測到一個因素,量越大的數字,但保持比較列表被遇到了:無法對一些

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

我目前擁有的代碼如下:

def MostComposite(integers): 
    #The item in sequence 'integers' of positive integers which has 
    #the greatest number of distinct factors, returns None if the sequence is empty. 
    mostComp = 0 
    for i in integers: 
     if (Factors(i)) > 0: 
      mostComp += i 
      if (Factors(i)) > mostComp: 
       mostComp += i 
    return mostComp 
+1

你比較'因素(我)'返回一個列表,'0'是一個整數。 –

+1

你大概想'len(因素(我))' –

+0

我已經解決了這個問題,但是代碼仍然沒有返回具有最大分解因子的整數項,如果你不介意的話,你能請指向正確的方向。 – Tigerr107

回答

0

無法比較不同的對象類型。

如果要比較長度的使用len(Factors(i))。 您的代碼應該是這樣的:

def MostComposite(integers): 
    #The item in sequence 'integers' of positive integers which has 
    #the greatest number of distinct factors, returns None if the sequence is empty. 
    mostComp = 0 
    for i in integers: 
     if len(Factors(i)) > 0: 
      mostComp += i 
      if len(Factors(i)) > mostComp: 
       mostComp += i 
    return mostComp 
+0

嗨,我已經解決了這個問題,但是代碼仍然沒有返回具有最大分解因子的整數中的項目,如果您不介意的話,請您指出正確的方向。 – Tigerr107