Tuesday, March 15, 2016

A/L ICT 2015 Python Code for Structured Question

Write a Python program to record the marks obtained by students at the term test. Each student has sat for the same three papers and each mark was given as an integer value out of 100 marks. Each student is identified by a unique index member which is also an integer. You should record the marks of student in a text file named 'marks.txt' in the following format.

 lndex_no_l ,mark_ll ,mark_l2,mark_l3
 Index_no_2 ,mark_2l ,mark_22 ,mark_23

Answer

file = open("marks.txt", "a")
running=1
while (running ==1) :
    indexNo = raw_input("Enter Index No: ") 
    if (indexNo=="-1"):
        running=-1
    else :
        mark1 = raw_input("Enter marks 1: ") 
        mark2 = raw_input("Enter marks 2: ") 
        mark3 = raw_input("Enter marks 3: ") 
        str=indexNo + "," + mark1 +  "," + mark2 +  ","  + mark2 + "\n"
        file.write (str)
file.close()

No comments:

Post a Comment