-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmakeclass.py
More file actions
73 lines (51 loc) · 1.5 KB
/
makeclass.py
File metadata and controls
73 lines (51 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import sys
import pickle
def computeModeratedMarks(file1, file2):
'''
Objective: To compute moderated marks of students
Input Parameters: file1, file2: file names - string values
addPercent – numeric value
Return Value: None
Final outcome: A new file – file2 of moderated marks is produced
'''
try:
fIn = open(file1, 'r')
fOut = open(file2,'wb')
except IOError:
print("Problem in opening the file")
sys.exit()
line = fIn.readline()
while(line != ''):
sList = line.split(',')
try:
sList[0] = int(sList[0])
sList[2] = int(sList[2])
except IndexError:
print("Undefined Index")
sys.exit()
except (ValueError, TypeError):
print("Unsuccessful conversion to int")
sys.exit()
pickle.dump(sList, fOut)
line = fIn.readline()
fIn.close()
fOut.close()
fOut = open(file2, 'rb')
while True:
try:
print(pickle.load(fOut))
except EOFError:
break
def main():
'''
Objective: To compute moderated marks based on user input
Input Parameter: None
Return Value: None
'''
import sys
sys.path.append("/home/administrator")
file1 = input('Enter name of file containing marks:')
file2 = input('Enter output file for moderated marks:')
computeModeratedMarks(file1, file2)
if __name__=='__main__':
main()