You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
 
 

44 lines
942 B

  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()