-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfilecopy.py
More file actions
70 lines (50 loc) · 1.64 KB
/
filecopy.py
File metadata and controls
70 lines (50 loc) · 1.64 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
import sys
def computeModeratedMarks(file1, file2, addPercent):
'''
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,'w')
except IOError:
print("Problem in opening the file")
sys.exit()
line = fIn.readline()
while(line != ''):
sList = line.split(',')
try:
rollNo = int(sList[0])
name = sList[1]
marks = int(sList[2])
except IndexError:
print("Undefined Index")
sys.exit()
except (ValueError, TypeError):
print("Unsuccessful conversion to int")
sys.exit()
maxMarks= 100
moderatedMarks = int(marks) + ((addPercent * maxMarks)/100)
if moderatedMarks > 100:
moderatedMarks = 100
fOut.write(str(rollNo) + ',' + name + ',' +str(moderatedMarks) + '\n')
line = fIn.readline()
fIn.close()
fOut.close()
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:')
addPercent = int(input('Enter moderation percentage:'))
computeModeratedMarks(file1, file2, addPercent)
if __name__=='__main__':
main()