-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssignment-5_python
145 lines (122 loc) · 4.55 KB
/
Assignment-5_python
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
The academic office at the Hogwarts School of Witchcraft and Wizardry has compiled data about students' grades.
The data is provided as text from standard input in three parts: information about courses, information about students and information about grades.
Each part has a specific line format, described below..
1) Information about courses
Line format: Course Code~Course Name~Semester~Year~Instructor
2) Information about students
Line format: Roll Number~Full Name
3) Information about grades
Line format: Course Code~Semester~Year~Roll Number~Grade
The possible grades are A, AB, B, BC, C, CD, D with corresponding grade points 10, 9, 8, 7, 6, 5 and 4.
The grade point average of a student is the sum of his/her grade points divided by the number of courses.
For instance, if a student has taken two courses with grades A and C, the grade point average is 8.50 = (10+7)÷2.
If a student has not completed any courses, the grade point average is defined to be 0.
You may assume that the data is internally consistent. For every grade, there is a corresponding course code and roll number in the input data.
Each section of the input starts with a line containing a single keyword. The first section begins with a line containing Courses.
The second section begins with a line containing Students. The third section begins with a line containing Grades.
The end of the input is marked by a line containing EndOfInput.
Write a Python program to read the data as described above and print out a line listing the grade point average for each student in the following format:
Roll Number~Full Name~Grade Point Average
Your output should be sorted by Roll Number. The grade point average should be rounded off to 2 digits after the decimal point. Use the built-in function round().
Here is a sample input and its corresponding output.
Sample Input:-
Courses
TRAN~Transfiguration~1~2011-2012~Minerva McGonagall
CHAR~Charms~1~2011-2012~Filius Flitwick
Students
SLY2301~Hannah Abbott
SLY2302~Euan Abercrombie
SLY2303~Stewart Ackerley
SLY2304~Bertram Aubrey
SLY2305~Avery
SLY2306~Malcolm Baddock
SLY2307~Marcus Belby
SLY2308~Katie Bell
SLY2309~Sirius Orion Black
Grades
TRAN~1~2011-2012~SLY2301~AB
TRAN~1~2011-2012~SLY2302~B
TRAN~1~2011-2012~SLY2303~B
TRAN~1~2011-2012~SLY2305~A
TRAN~1~2011-2012~SLY2306~BC
TRAN~1~2011-2012~SLY2308~A
TRAN~1~2011-2012~SLY2309~AB
CHAR~1~2011-2012~SLY2301~A
CHAR~1~2011-2012~SLY2302~BC
CHAR~1~2011-2012~SLY2303~B
CHAR~1~2011-2012~SLY2305~BC
CHAR~1~2011-2012~SLY2306~C
CHAR~1~2011-2012~SLY2307~B
CHAR~1~2011-2012~SLY2308~AB
EndOfInput
Sample Input
SLY2301~Hannah Abbott~9.5
SLY2302~Euan Abercrombie~7.5
SLY2303~Stewart Ackerley~8.0
SLY2304~Bertram Aubrey~0
SLY2305~Avery~8.5
SLY2306~Malcolm Baddock~6.5
SLY2307~Marcus Belby~8.0
SLY2308~Katie Bell~9.5
SLY2309~Sirius Orion Black~9.0
Program:
def Gvalue(code):
if code=="A":
return(10)
if code=="AB":
return(9)
if code=="B":
return(8)
if code=="BC":
return(7)
if code=="C":
return(6)
if code=="CD":
return(5)
if code=="D":
return(4)
ROLL_GRADEsum={}
Roll_course_count={}
Roll_name={}
#courses section
type_course=input()
enter_course_detail=input()
next_input=input()
while(next_input!="Students"):
next_input=input()
#student section
#if it fails in courses section then
#it will enter students
roll,name=input().split('~')
Roll_name[roll]=name
ROLL_GRADEsum[roll]=0
Roll_course_count[roll]=0
next_input=input()
while('~' in next_input):
roll,name=next_input.split('~')
Roll_name[roll]=name
ROLL_GRADEsum[roll]=0
Roll_course_count[roll]=0
next_input=input()
#GRADES SECTION
code,sem,year,Rnum,grade=input().split('~')
if Rnum in ROLL_GRADEsum.keys():
ROLL_GRADEsum[Rnum]=ROLL_GRADEsum[Rnum]+Gvalue(grade)
Roll_course_count[Rnum]=Roll_course_count[Rnum]+1
next_input=input()
while(next_input!="EndOfInput"):
code,sem,year,Rnum,grade=next_input.split('~')
if Rnum in ROLL_GRADEsum.keys():
ROLL_GRADEsum[Rnum]=ROLL_GRADEsum[Rnum]+Gvalue(grade)
Roll_course_count[Rnum]=Roll_course_count[Rnum]+1
next_input=input()
#print(Roll_course_count)
#print(ROLL_GRADEsum)
#print(Roll_name)
Sort_roll=sorted(Roll_name)
for key in Sort_roll:
if ROLL_GRADEsum[key]!=0:
ans=round((ROLL_GRADEsum[key]/Roll_course_count[key]),2)
print(key+"~"+Roll_name[key]+"~"+str(ans))
else:
print(key+"~"+Roll_name[key]+"~"+"0")