Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Information about courses
Line format: Course Code~Course Name~Semester~Year~Instructor
Information about students
Line format: Roll Number~Full Name
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


What I have tried:

Python
(lis1, lis2, lis3)= ([], [], [])
 
a = input()
while True:
	
	if a == 'Courses':
		a =input()
		while a != 'Students':
			lis1.append(a.split('~'))
			a = input()
	elif a == 'Students':
		a =input()
		while a!= 'Grades':
			a.split(' ')
			lis2.append(a.split('~'))
			a = input()
	elif a == 'Grades':
		a =input()
		while a != 'EndOfInput':
			lis3.append(a.split('~'))
			a = input()
	elif a == 'EndOfInput':
		break
	else:
		break

i have been successful in making separate list of Course(lis1), Students(lis2), Grades(lis3) but i Don't know what to do next and how to approach further plz help!!. I guess i require dictionaries too. also how can i calculate gradepoint from letters and how to finally join al the specific values. I gues Join method of python shall be helpful but i am not getting how to arrange all parameters
Posted
Updated 2-Sep-17 1:55am
v2

At a guess you need to go through the grade records and look up the student for each one. Using the letter grades you can get the numeric value, and add that to the student total. Once you have added all the grade values you can calculate the averages. You may find it useful to create a class to hold all the information for each student, rather than using simple lists.

[edit]
I see you have already posted this question using a different account (Please solve this Python program[^]). Please do not create multiple accounts and do not repost the same question.
[/edit]
 
Share this answer
 
v2
Comments
OriginalGriff 2-Sep-17 4:25am    
But ... but ... but ... he says "I am another user facing the same problem" and you don't believe him? :laugh:
Member 13389943 2-Sep-17 5:02am    
Haha...i am a different person man😁😁
Richard MacCutchan 2-Sep-17 5:06am    
Yes of course you are. Strange how you both have exactly the same text in your questions.
Member 13389943 2-Sep-17 5:03am    
We have not learnt classes(oop) yet!!
Still it's not clear to me
Richard MacCutchan 2-Sep-17 5:06am    
Fine, then use something that you have learnt. Most importantly use your course notes.
# Setting the grades to their numerical values
def convert_grade(grade):
if grade == 'A':
return 10
elif grade == 'AB':
return 9
elif grade == 'B':
return 8
elif grade == 'BC':
return 7
elif grade == 'C':
return 6
elif grade == 'CD':
return 5
elif grade == 'D':
return 4
else:
return 0


# Create 3 lists
(course_list, student_list, grade_list) = ([], [], [])

# Take the input
inp = input()


while True:

if inp == 'Courses':
inp = input()
while inp != 'Students':
course_list.append(inp.split('~'))
inp = input()

elif inp == 'Students':
inp = input()
while inp != 'Grades':
inp.split(' ')
student_list.append(inp.split('~'))
inp = input()

elif inp == 'Grades':
inp = input()
while inp != 'EndOfInput':
grade_list.append(inp.split('~'))
inp = input()
elif inp == 'EndOfInput':
break
else:
break

no_of_course = len(course_list)
roll_list = []
name_list = []
trans_grade = []

# Get the Roll Numbers
for i in range(0,len(student_list)):
roll_list.append(student_list[i][0])
name_list.append(student_list[i][1])

# Getting the grade for each student
avg_grade = []

for i in range(0,len(grade_list)):
for j in range(i+1, len(grade_list)):
if grade_list[i][3] == grade_list[j][3]:
avg_grade.append((convert_grade(grade_list[i][4]) + convert_grade(grade_list[j][4]))/(no_of_course))


print (avg_grade)
print (roll_list)
print (name_list)

print (course_list)
print (student_list)
print (grade_list)
 
Share this answer
 
Comments
Dave Kreskowiak 2-Sep-17 11:24am    
I'm sorry, when did you get into the habit of doing someones homework for them?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900