#방식 (1) : c언어 비슷한 구조
name_list = ['Kim', 'Lee', 'Park']
kor = [ 100, 80, 95 ]
math = [ 94, 79, 88 ]
eng = [ 60, 90, 55 ]
total_info = [ name_list, kor, math, eng ]
print(total_info[0][0] )
print(total_info[0][1] )
print(total_info[0][2] )
sum_kor = 0
sum_math = 0
sum_eng = 0
for i in range(0, 3, 1):
sum_kor = sum_kor + total_info[1][i]
sum_math = sum_math + total_info[2][i]
sum_eng = sum_eng + total_info[3][i]
avg_kor = sum_kor/3
avg_math = sum_math/3
avg_eng = sum_eng/3
print(avg_kor)
print(avg_math)
print(avg_eng)
#방식 (2) : Python 형식의 구조
name_list = ['Kim', 'Lee', 'Park']
for = [ 100, 80, 95 ]
math = [ 94, 79, 88 ]
eng = [ 60, 90, 55 ]
total_info = [ name_list, kor, math, eng ]
print(total_info[0][0] )
print(total_info[0][1] )
print(total_info[0][2] )
avg = []
for i in range(3):
sum = 0
for j in range(1, 4, 1):
sum += total info[j][i]
avg.append(sum//3)
total_info.append(avg)
for i in range(5):
print(total_info[i] )
#방식 (3) : 응용 형태
Kim = [ 100, 94, 60 ]
Lee = [ 94, 76, 88 ]
Park = [ 60, 90, 55 ]
lst [ Kim, Lee, Park ]
kor_avg = 0
math_avg = 0
English_avg = 0
for i in range(len(lst) ):
kor_avg += lst[i][0]
math_avg += lst[i][1]
eng_avg += lst[i][2]
print("국어 평균 : %0.2f" %kor_avg/len(lst) )
print("수학 평균 : %0.2f" %math_avg/len(lst) )
print("영어 평균 : %0.2f" %eng_avg/len(lst) )
'Python > Example' 카테고리의 다른 글
[Python] 예제 (함수) (0) | 2021.02.26 |
---|---|
[Python] 예제 - 전화번호부 생성(Tuple) (0) | 2021.02.26 |
[Python] 예제 (최댓값 구하기 / 여러 응용) (0) | 2021.02.26 |
[Python] 예제 (for문 안에 if문 활용) (0) | 2021.02.26 |
댓글