Students mark validation

# File handling 

# Student mark validation 


fs = None


try:

fs = open("MarkList.txt","r")

for line in fs:

L = line.split()

Name = L[0]

marklist = [int(m) for m in L[1:]]

for mark in marklist:

if(mark<0 or mark>100):

print(Name,end=" - ")

raise ValueError

if(all(m>=50 for m in marklist)):

print(Name, "- Grade - Pass.",end=" ")

print("Score = ", sum(marklist),end=" ")

print("Average = ",round((sum(marklist)/len(marklist)),2))

else:

print(Name, "- Grade - Fail.")

except IOError as e:

print("File opening error : ", e)

except (ValueError):

print("Value Error: invalid mark value.") 

except:

print("unknown error")


finally:

print("End of mark validation.")

if(fs):

fs.close()

"""

Sample Output 1


Input file: MarkList.txt

Alice 28 58 74

Cathy 60 76 56

Frank 47 56 67

Irene 92 87 76

Kelly 15 35 56


>python Files_MarkValidation.py

Alice - Grade - Fail.

Cathy - Grade - Pass. Score =  192 Average =  64.0

Frank - Grade - Fail.

Irene - Grade - Pass. Score =  255 Average =  85.0

Kelly - Grade - Fail.

End of mark validation.


************************************************

 

Sample Output 2


Input file: MarkList.txt

Alice 28 58 74

Cathy 60 76 56

Frank -47 56 67

Irene 92 87 76

Kelly 15 35 56


>python Files_MarkValidation.py

Alice - Grade - Fail.

Cathy - Grade - Pass. Score =  192 Average =  64.0

Frank - Value Error: invalid mark value.

End of mark validation.


"""

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu