您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. def parse_scores():
  2. res = dict()
  3. with open("scores.txt") as file:
  4. for line in file.readlines():
  5. name, score = line.split()
  6. res[name] = int(score)
  7. return res
  8. scores = { "joe" : 42, "jack" : 43 }
  9. print (convert(scores))
  10. def print_scores(scores):
  11. print("Tableau des résultats:")
  12. for name, score in scores.items():
  13. print(name, score)
  14. def convert(scores):
  15. res = ""
  16. for name, score in scores.items():
  17. res += name + " " + str(score) + "\n"
  18. return res
  19. def register_score(scores, name, new_score):
  20. # Mise à jour des tableaux des scores
  21. # Et écriture dans un fichier
  22. scores[name] = new_score
  23. with open("scores.txt", "w") as file:
  24. file.write(convert(scores))
  25. def main():
  26. scores = parse_scores()
  27. name = input("nom: ")
  28. new_score = input("score: ")
  29. register_score(scores, name, new_score)
  30. print_scores(scores)
  31. main()