Skip to content
ExamSpine

Answer it

Write mode or append mode for quiz results

4 marksYou mark it yourself against the marking points

A revision quiz saves each player's result to results.txt by calling this function. Here is the program.

def save_result(name, score):
    f = open("results.txt", "w")
    f.write(name + "," + str(score) + "\n")
    f.close()

save_result("Ana", 8)
save_result("Ben", 6)
save_result("Cal", 9)
static void saveResult(String name, int score) throws IOException {
    FileWriter writer = new FileWriter("results.txt");
    writer.write(name + "," + score + "\n");
    writer.close();
}

// in main
saveResult("Ana", 8);
saveResult("Ben", 6);
saveResult("Cal", 9);

(a) State what results.txt contains after the three calls. [1]

(b) Explain why the file holds this. [2]

(c) State the change to the first line of the function body so that every result is kept. [1]

[4]

Report a problem with this page