dimanche 20 décembre 2015

How do you limit the inclusion of a specific input in a text file

Im trying to save student's scores in a text file however I have been asked to save the student's last three scores. This sounded fairly straight forward however after attempting various different things I still can't do it. I have been trying to use their names as the variable that changes i.e. if their name is entered more than once.

here is my pitiful best attempt please help

class_number = prompt_int_big("Before your score is saved ,are you in class 1, 2 or 3? Press the matching number")

    filename = (str(class_number) + "txt")
    if any(name in s for s in filename):
        for score in range (0,3):
            with open(filename, 'a') as f:
                f.write("\n" + str(name) + " also scored " + str(score) +  " on difficulty level " + str(level_of_difficulty) + "\n")
            with open(filename) as f:
                lines = [line for line in f if line.strip()]
                lines.sort()
            name[-3]
    else:
        with open(filename, 'a') as f:
            f.write("\n" + str(name) + " scored " + str(score) +  " on difficulty level " + str(level_of_difficulty) + "\n")
        with open(filename) as f:
            lines = [line for line in f if line.strip()]
            lines.sort()




Aucun commentaire:

Enregistrer un commentaire