The Student Room Group

OCR Unit A453 - Maths Quiz on Task 2

Hi, I have started on Task 2 of my Maths Quiz. When I looked at the scenario, I thought it would look a little bit simple to do - all it was to do is file read and write on the information of the quiz.

Here is the scenario for task 2:
"The teacher wants to keep tack of the scores each member of the class obtains in the quiz. There are three classes in the school and the data should be kept separately for each class.

Analyse the requirements in detail for this program and design, code, test and evaluate a program will record and store the data for three separate classes of students using the arithmetic quiz."

For what I am doing is adding a bit of code that will make a text file at the end of the quiz. So, when a user has finished the quiz, the score will be recorded in to a text file with the name. The text file must be named with a class number.

Here is my code, but doesn't work:
filename = class_name + ".txt"
file = open(class_name , 'a':wink:
file.write(name + "with ",str(correct_questions) + "out of 10.":wink:
file.write('\n':wink:
file.close()

Much help would be needed as appreciated. My deadline for this is next week, so I need a quick response. Apart from that, I will carry on the research and I will give you a solution if I managed to get it to work for my quiz.

Many thanks,

BH1603
Reply 1
I have figured out that this bit of program does work, but I want it so that the information gets to be put on automatically instead of me typing it in the program manually.

The program:
with open("ClassScores.txt", "a") as my_file:
username = 'Ben' # I want this to be someones name as someone inputs their name in before the quiz starts.
class_name = 3 # Want the input from the user, not from the program.
correct_answers = 10 # When the quiz finishes, the file should update when the results have been resulted.

my_file.write("{} in class {} with {} out of 10.\n".format(username,class_name,correct_answers)) # This is okay, no need to change anything here.
Original post by BH1603
I have figured out that this bit of program does work, but I want it so that the information gets to be put on automatically instead of me typing it in the program manually.

The program:
with open("ClassScores.txt", "a":wink: as my_file:
username = 'Ben' # I want this to be someones name as someone inputs their name in before the quiz starts.
class_name = 3 # Want the input from the user, not from the program.
correct_answers = 10 # When the quiz finishes, the file should update when the results have been resulted.

my_file.write("{} in class {} with {} out of 10.\n".format(username,class_name,correct_answers)) # This is okay, no need to change anything here.



So, without helping you too much, saving a users input as a variable isn't that hard.

ex.
name = input("What is your name")
Will firstly ask the user 'What is your name?' in console and the users response will then be stored as the 'name' variable.

Quick Reply

Latest

Trending

Trending