如何进一步解决以下问题? [英] How do I approach further in the following problem?

查看:80
本文介绍了如何进一步解决以下问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

课程信息

行格式:课程代码〜课程名称〜学期〜年级〜讲师

学生信息

行格式:卷号〜全名

关于成绩的信息

行格式:课程代码〜学期〜年〜卷号〜年级

可能的成绩是A,AB,B,BC,C,CD,D以及相应的成绩点10,9,8,7,6,5和4.学生的平均成绩是他/她的成绩点除以课程数量。例如,如果学生参加了两门A和C级课程,则平均成绩为8.50 =(10 + 7)÷2。如果学生没有完成任何课程,则平均成绩点定义为0.



您可以假设数据内部一致。对于每个等级,输入数据中都有相应的课程代码和卷号。



输入的每个部分都以包含单个关键字的行开头。第一部分以包含课程的一行开头。第二部分以包含学生的一行开头。第三部分以包含成绩的行开头。输入的结尾用包含EndOfInput的行标记。



写一个Python程序来读取上面描述的数据并打印出列出平均成绩点的行对于每个学生,格式如下:



卷号〜全名〜平均成绩点

您的输出应按卷号排序。等级点平均值应舍入为小数点后的2位数。使用内置函数round()。



这是一个示例输入及其相应的输出。



样本输入

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:

(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已成功制作单独的课程列表(lis1),学生(lis2),成绩(lis3),但我不知道接下来该做什么以及如何进一步接近请帮助!!我想我也需要字典。我如何从字母计算成绩点以及如何最终加入特定值。我猜对象的python方法应该会有所帮助,但我没有得到如何安排所有参数


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

推荐答案

猜测你需要通过成绩记录并查找每个人的学生。使用字母等级,您可以获得数字值,并将其添加到学生总数中。添加完所有成绩后,您可以计算平均值。您可能会发现创建一个类可以保存每个学生的所有信息,而不是使用简单的列表。



[edit]

我发现您已经使用其他帐户发布了此问题(请解决此Python程序 [ ^ ])。请不要创建多个帐户,也不要重新发布相同的问题。

[/ edit]
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]


#将等级设置为其数值

def convert_grade(等级):

如果等级=='A':

返回10

elif等级=='AB' :

返回9

elif等级=='B':

返回8

elif等级==' BC':

返回7

elif等级=='C':

返回6

elif等级= ='CD':

返回5

elif等级=='D':

返回4

else :

返回0





#创建3个列表

(course_list, student_list,grade_list)=([],[],[])



#接受输入

inp = input()





而True:



如果inp =='课程':

inp =输入()

w hile inp!='学生':

course_list.append(inp.split('〜'))

inp = input()



elif inp =='学生':

inp =输入()

而inp!='成绩':

inp.split('')

student_list.append(inp.split('〜'))

inp = input()



elif inp =='等级':

inp =输入()

而inp!='EndOfInput':

grade_list.append(inp.split('〜'))

inp = input()

elif inp =='EndOfInput':

休息

其他:

休息



no_of_course = len(course_list)

roll_list = []

name_list = []

trans_grade = []



#得到滚动号码

for i in range(0,len(student_list)):

roll_list.append(student_list [i] [0])

name_list.append(student_ list [i] [1])



#获得每个学生的成绩

avg_grade = []



我在范围内(0,len(grade_list)):

为范围内的j(i + 1,len(grade_list)):

如果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 )

打印(name_list)



打印(course_list)

打印(student_list)

print(grade_list)
# 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)


这篇关于如何进一步解决以下问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆