Answers for "save score code"

0

save score code

import shelve

scoreFile = shelve.open('score.txt')

def updateScore(newScore):
  if('score' in scoreFile):
    score = scoreFile['score']
    if(newScore not in score):
      score.insert(0, newScore)

    score.sort()
    ranking = score.index(newScore)
    ranking = len(score)-ranking
  else:
    score = [newScore]
    ranking = 1

  print(score)
  print(ranking)
  scoreFile['score'] = score
  return ranking

newScore = int(input("New HighScore: \n"))
updateScore(newScore)
Posted by: Guest on July-16-2020

Python Answers by Framework

Browse Popular Code Answers by Language