Ad
  • Custom User Avatar

    Still stuck, here is what I have so far. I tried putting the entire code into a Try Except - but it still didn't show me the test case that was failing. Passing all the basic tested up to #18

    def rank(st=9999, we=9999, n=9999):
    try:
    print(st,we,n)
    st = st.split(',')

        alpha_score = {
            'a':1,
            'b':2,
            'c':3,
            'd':4,
            'e':5,
            'f':6,
            'g':7,
            'h':8,
            'i':9,
            'j':10,
            'k':11,
            'l':12,
            'm':13,
            'n':14,
            'o':15,
            'p':16,
            'q':17,
            'r':18,
            's':19,
            't':20,
            'u':21,
            'v':22,
            'w':23,
            'x':24,
            'y':25,
            'z':26,
        }
    
        if st == 9999:
            return 'No participants'
    
        elif st[0].isalpha():
        
        #try:
            if n > len(st):
                return 'Not enough participants'
        
        
            else:
                n = n - 1
                score_list = []
                name_list = []
                sorted_name_list = []
                sorted_score_list = []
                score_name = {}
    
                for name in st:
    
                    som = 0
                    som += len(name)
                    for letter in name.lower():
                        som += alpha_score[letter]
                    som = som * we.pop(0)
                    if som in score_list:
                        name_confirm = []
                        name_confirm.append(score_name[som])
                        name_confirm.append(name)
                        name_confirm.sort()
                        if name_confirm[0] == name:
                            som += .01
                            score_list.append(som)
                            score_name[som] = name
                        else:
                            som -= .01
                            score_list.append(som)
                            score_name[som] = name
                        
                    else:
                        score_list.append(som)
                        score_name[som] = name
                
                for k,v in sorted(score_name.items(), reverse=True):
                    sorted_score_list.append(k)
                    sorted_name_list.append(v)
    
            return sorted_name_list[n]
    #except:
            print(st, we, k)
        
        else:
            return 'No participants'
    except IndexError:
        print(st, we, k)
    
  • Default User Avatar

    I'm trying to solve this with python and I am getting the following:
    STDERR
    Traceback (most recent call last):
    File "main.py", line 85, in
    randomTests()
    File "main.py", line 83, in randomTests
    Test.assert_equals(rank(st, we, k), rankSol(st, we, k))
    File "main.py", line 52, in rankSol
    res.append([f[i], we[i] * scoreSol(f[i])])
    IndexError: list index out of range

    I know list index out of range is usually from calling an out of range index value on a list, like lista = [0, 1, 2] and then I try and run lista[3] but I am not really sure where this could be happening in my code. Any thoughts are appreciated!

    Thanks!