From cc, 9 Months ago, written in Plain Text.
Embed
Hits: 452
1. # ----------Du lieu
2. import pandas as pd
3. STT=[]
4. listTen=[]
5. listToan=[]
6. listLy=[]
7. listHoa=[]
8. #----------Ham
9. def nhapLieu(n):
10.     for x in range (1,n+1):
11.         STT.append('sv'+str(x))
12.         listTen.append(input('Moi Nhap Ten :'))
13.         listToan.append(int(input('Moi Nhap Diem Toan :')))
14.         listLy.append(int(input('Moi Nhap Diem Ly :')))
15.         listHoa.append(int(input('Moi Nhap Diem Hoa :')))
16. def trungbinhTLH(df):
17.     diemTB=(df['Toan']+df['Ly']+df['Hoa'])/3
18.     return diemTB
19. def maxTLH(df):
20.     maxToan=max(df['Toan'])
21.     maxLy=max(df['Ly'])
22.     maxHoa=max(df['Hoa'])
23.     return [maxToan,maxLy,maxHoa]
24. def minTLH(df):
25.     minToan=min(df['Toan'])
26.     minLy=min(df['Ly'])
27.     minHoa=min(df['Hoa'])
28.     return [minToan,minLy,minHoa]
29. def lonNhiTLH(df):
30.     tempToan=list(df['Toan'])
31.     tempLy=list(df['Ly'])
32.     tempHoa=list(df['Hoa'])
33.     tempToan.sort()
34.     tempLy.sort()
35.     tempHoa.sort()
36.     return[tempToan[-2],tempLy[-2],tempHoa[-2]]
37. def lonBaTLH(df):
38.     tempToan=list(df['Toan'])
39.     tempLy=list(df['Ly'])
40.     tempHoa=list(df['Hoa'])
41.     tempToan.sort()
42.     tempLy.sort()
43.     tempHoa.sort()
44.     return[tempToan[-3],tempLy[-3],tempHoa[-3]]
45. #----------Main
46. print("Nhap lieu Sinh vien")
47. n=int(input("Nhap So Luong Sinh vien"))
48. nhapLieu(n)
49. tempDict={'STT':STT,'Ten':listTen,'Toan':listToan,'Ly':listLy,'Hoa':listHoa}
50. df= pd.DataFrame(tempDict)
51. df
52.
53. #-----------Diem Trung Binh TLH
54. diemTB=trungbinhTLH(df)
55. df['DiemTB']=diemTB
56. print(df)
57. #----------Max Toan Ly Hoa
58. lonNhatTLH=maxTLH(df)
59. tempMaxDict={'STT':'Max','Toan':lonNhatTLH[0],'Ly':lonNhatTLH[1],'Hoa':lonNhatTLH[2]}
60. maxDF= pd.DataFrame(tempMaxDict,index=[n])
61. df1=pd.concat([df,maxDF])
62. df1
63. #---------Min Toan Ly Hoa
64. nhoNhatTLH=minTLH(df)
65. tempMinDict={'STT':'Min','Toan':nhoNhatTLH[0],'Ly':nhoNhatTLH[1],'Hoa':nhoNhatTLH[2]}
66. minDF= pd.DataFrame(tempMinDict,index=[n+1])
67. df2=pd.concat([df1,minDF])
68. df2
69. #---------Lon nhi
70. nhoNhi=lonNhiTLH(df)
71. nhoNhiDict={'STT':'Lon Nhi','Toan':nhoNhi[0],'Ly':nhoNhi[1],'Hoa':nhoNhi[2]}
72. nhoNhiDF= pd.DataFrame(nhoNhiDict,index=[n+2])
73. df3=pd.concat([df2,nhoNhiDF])
74. df3
75.
76. #---------Lon ba
77. nhoBa=lonBaTLH(df)