-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path다중리스트_성적연산.py
37 lines (31 loc) · 1.09 KB
/
다중리스트_성적연산.py
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
Num_Student=4
Num_Subject=5
Identity=['Trump','Putin','Obama','Xijinping']
Grade=[['C','B','A','C','D'],
['F','D','C','D','B'],
['A','B','A','B','A'],
['A','A','B','C','D']]
Rank=[1,2,3,4]
Credit=[3,3,3,2,1]
Grade_Avg=[0.00]*Num_Student
for i in range(Num_Student):
total_grade=0
total_Credit=0
for j in range(Num_Subject):
if Grade[i][j]=='A' : total_grade += 4.0*Credit[j]
elif Grade[i][j]=='B' : total_grade += 3.0*Credit[j]
elif Grade[i][j]=='C' : total_grade += 2.0*Credit[j]
elif Grade[i][j]=='D' : total_grade += 1.0*Credit[j]
total_Credit+=Credit[j]
Grade_Avg[i]=total_grade/total_Credit
for i in range(Num_Student):
for j in range(i,Num_Student):
if Grade_Avg[i]<Grade_Avg[j]:
tmp=Grade_Avg[i]
Grade_Avg[i]=Grade_Avg[j]
Grade_Avg[j]=tmp
tmp=Identity[i]
Identity[i]=Identity[j]
Identity[j]=tmp
for i in range(Num_Student):
print("%d %s %.2f"%(Rank[i],Identity[i],Grade_Avg[i]))