Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    4
    ReputationRep:
    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'
    file.write(name + "with ",str(correct_questions) + "out of 10."
    file.write('\n'
    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
    • Thread Starter
    Offline

    4
    ReputationRep:
    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_nam e,correct_answers)) # This is okay, no need to change anything here.
    Offline

    7
    ReputationRep:
    (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" 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_nam e,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.
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    What's your favourite Christmas sweets?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.