Python运行时错误:TypeError:'NoneType'对象不可迭代(Hackerrank练习)

时间:2018-10-20 10:12:08

标签: python runtime-error typeerror

我正在从事这项运动

https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem

Python确实引发了运行时错误:

Traceback (most recent call last):
  File "solution.py", line 36, in <module>
    fptr.write('\n'.join(map(str, result)))
TypeError: 'NoneType' object is not iterable

我只编写了climbingLeaderbord函数,其余的代码已经提供给我了。当我打印结果时,它表明我的解决方案是正确的,但是Python仍然给我运行时错误。我做错了什么?

import math
import os
import random
import re
import sys

def climbingLeaderboard(scores, alice):
    for i in range(0, len(alice)):
        rank = 1
        scores_ident = 0
        for j in range(0, len(scores)):            
            if alice[i] < scores[j]:
                rank = rank + 1
                if j > 0 and scores[j] == scores[j-1]:
                    scores_ident = scores_ident + 1
        rank = rank - scores_ident
        print(rank)

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    scores_count = int(input())

    scores = list(map(int, input().rstrip().split()))

    alice_count = int(input())

    alice = list(map(int, input().rstrip().split()))

    result = climbingLeaderboard(scores, alice)

    fptr.write('\n'.join(map(str, result)))
    fptr.write('\n')

    fptr.close()

0 个答案:

没有答案