File size: 798 Bytes
b33d6d1
 
 
e2782ab
 
b33d6d1
e2782ab
 
b33d6d1
 
e2782ab
 
 
b33d6d1
e2782ab
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21


def add_guess(guess_result, guessed, guesses):
    word, sim, rank = guess_result
    if sim:
        if word not in guessed:
            sim = round(sim, 2)
            rank = "情報なし" if rank == 1001 else rank
            guesses.loc[len(guessed)] = ([len(guessed), word, sim, rank])
            guessed.add(word)
        cur_result = format_result(word, sim, rank)
    else:
        cur_result =  "不正解: 正しくない単語"
    return "\n".join([cur_result, "最高スコア:", format_table(guesses)]), guessed, guesses

def format_result(word, sim, rank):
    return f"{word}: スコア {sim}, ランク {rank}"

def format_table(table, n_rows=10):
    top_results = table.sort_values(by="スコア", ascending=False).head(n_rows)
    return top_results.to_markdown(index=False)