2016-09-28 12 views
1

私の学校のプロジェクトに取り組んでいます。私は、ビッグバナーでリーダーボードを作る方法があるのだろうかと思っていましたか?私はかなりPythonの新しいですが、これまでのところ、私がやったことは、ユーザーの入力を取得し、それをテキストファイルに格納することです。私はどのように続行するか分からない。どんな助けでも感謝しています!あなたはどのようにリーダーボードを作るのですか?

x = 0 

Name = [None]*1000 
Class = [None]*1000 
Score = [0]*100 

# opens the text file called text_file 
text_file = open("write.txt","a") 

# puts in the values of the highest scores and "saves it" by closing and opening the file 
def write_in_file(): 
    global text_file 
    text_file.write(Name[x]) 
    text_file.write("\n") 
    text_file.write(Class[x]) 
    text_file.write("\n") 
    text_file.write(Score[x]) 
    text_file.write("\n") 
    text_file.write("\n") 
    text_file.close() 
    text_file = open("write.txt","a") 

# asks for player data and puts highest value in a file 
for i in Name: 
    Name[x] = input("Name:") 
    Class[x] = input("Class:") 
    Score[x] = input("Score:") 
    write_in_file() 
    print(Score) 
    x += 1 
+0

また、この出力を投稿できますか?名前でスコアをソートする必要がありますか? –

+0

あなたは特定のことをやろうとしていますか? – Holloway

+0

リラックスして論理を考えましょう。 最終的な目標は、さまざまなユーザー間のスコアを比較し、数字に応じて並べ替えることです。したがって、 1.新しいユーザーをどのように挿入しますか? 2.新しいクラスをどのように挿入しますか? 3.同じクラス/異なるクラスのユーザーをどのように比較しようとしていますか? 4.どのようにユーザーをランク付けしますか? ちょうどリラックスして、あなたのベストを考えてみてください。 – PSone

答えて

1

リーダーボードテーブルの作成にはpandasを使用できます。ここにサンプルがあります。

import pandas as pd 

df = pd.DataFrame({'Name': ['x','y','z'], 
        'Class': ['B','A','C'], 
        'Score' : [75,92,56]}) 
print (df) 

Out[3]: 
    Class Name Score 
0  B x  75 
1  A y  92 
2  C z  56 


# changing order of columns 
df = df.reindex_axis(['Name','Class','Score'], axis=1) 

# appending 
df.loc[3] = ['a','A', 96] 

print (df) 

Out[15]: 
    Name Class Score 
1 y  A  92 
3 a  A  96 
0 x  B  75 
2 z  C  56 

# sorting 
df = df.sort(['Class', 'Score'], ascending=[1, 0]) 

print (df) 

Out[16]: 
    Name Class Score 
3 a  A  96 
1 y  A  92 
0 x  B  75 
2 z  C  56 
関連する問題