Ad
  • Custom User Avatar

    same problem

  • Default User Avatar

    I understand that since so many people have completed this task, it is most likely my fault, but I still do not understand. The error message says that the error is in the tests. I also checked the execution of my code on prints in cases where an error occurs and the code is executed to the end without problems, but the index error still occurs in the test.

  • Custom User Avatar

    PYTHON

    Help me please! I don't understand what the problem is. On my computer, the same code with the same input data is executed without errors.

    Code:

    def rank(st, we, n):

    names = st.split(',')
    if not st: return "No participants"
    if n > len(names): return "Not enough participants"
    som_names = []
    alp_ranks = {chr(rank): rank - 96 for rank in range(97, 123)}
    
    for name in names:
        som = (sum([alp_ranks[letter.lower()] for letter in name]) + len(name)) * we.pop(0)
        som_names.append([som, name])
    
    som_names = sorted(som_names, key=lambda x: x[1], reverse=False)
    som_names = sorted(som_names, key=lambda x: x[0], reverse=True)
    
    return som_names[n-1][1]
    

    Error:

    Traceback (most recent call last):
    File "/workspace/default/.venv/lib/python3.10/site-packages/codewars_test/test_framework.py", line 112, in wrapper
    func()
    File "/workspace/default/tests.py", line 87, in randomTests
    test.assert_equals(rank(st, we, k), rankSol(st, we, k))
    File "/workspace/default/tests.py", line 56, in rankSol
    res.append([f[i], we[i] * scoreSol(f[i])])
    IndexError: list index out of range