Pusan National University power PNU Spring 2019 School
- Slides: 31
Pusan National University power PNU 세계로 미래로 간단한 통계처리 프로그램 만들기 Spring, 2019 School of CSE Pusan National University http: //cfile 5. uf. tistory. com/image/2178384951789 FFF 080 F 11
세계로 미래로 power PNU 합계(sum)와 평균(average) 구하기 배열에 들어있는 정수의 합계와 평균 max_num_stu = 10 # const jeomsu = [0 for i in range(0, max_num_stu + 1)] for i in range(1, max_num_stu + 1): jeomsu[i] = i * 10 Advanced Broadcasting & Communications Lab. 2
세계로 미래로 power PNU 합계(sum)와 평균(average) 구하기 # end for i sum = 0 for i in range(1, max_num_stu + 1): sum = sum + jeomsu[i] # end for i if (max_num_stu != 0): # 나누기 0 조심 avg = float (sum) / max_num_stu else: avg = 0. 0 # end if print ("합계 = ", sum, "평균 = ", avg) Advanced Broadcasting & Communications Lab. 3
세계로 미래로 power PNU 합계(sum)와 평균(average) 구하기 • 프로그램을 실행하다가 0으로 나누게 되며, 프로그램은 error message를 찍고, 비정상적으로 끝나버린다. – Zero. Division. Error: float division by zero Advanced Broadcasting & Communications Lab. 4
세계로 미래로 power PNU 합계(sum)와 평균(average) 구하기 • 1 에서 n까지의 합계 구하기 (n 의 값은 파일에서 읽어 들인다: readline() file 1 = open("sum-in 12. txt", "r") line = file 1. readline () n = int (line) file 1. close() sum = 0 for i in range(1, n+1): sum = sum + i print ("1에서", n, "까지합계=", sum) Advanced Broadcasting & Communications Lab. 6
세계로 미래로 power PNU 합계(sum)와 평균(average) 구하기 if (n <= 0): avg = 0. 0 else: avg = float(sum) / n print ("평균=“, avg) Advanced Broadcasting & Communications Lab. 8
세계로 미래로 power PNU 합계(sum)와 평균(average) 구하기 • n 1에서 n 2까지의 합계와 평균 (n 1과 n 2는 파일에서 읽어들인다) file 1 = open("sum-in 21. txt", "r") line = file 1. readline() list 1 = line. split() If (len(list 1) >= 1): n 1 = int(list 1 [0]) else: n 1 = 0 print ("n 1(= 부터)의 값이 주어지지 않았음. . . “) If (len(list 1) >= 2): n 2 = int(list 1 [1]) Advanced Broadcasting & Communications Lab. 9
세계로 미래로 power PNU 합계(sum)와 평균(average) 구하기 else: n 2 = 0 print ("n 2 (= 까지)의 값이 주어지지 않았음. . . “) file 1. close() sum = 0 for i in range(n 1, n 2 + 1): sum = sum + i If (n 1 <= n 2): avg = sum / (n 2 - n 1 + 1) else: avg = 0. 0 print ("평균=“, avg) Advanced Broadcasting & Communications Lab. 10
세계로 미래로 power PNU 합계(sum)와 평균(average) 구하기 • 파일에 있는 모든 수의 합계와 평균을 구한다. count = 0; sum = 0 # ; 한 줄에 문장 여럿 file 1 = open("sum-in 31 x-empty. txt", "r") for line in file 1: num_read = int(line) count = count + 1 sum = sum + num_read file 1. close() if (count == 0): avg = 0. 0 else: avg = float (sum) / count print ("합계=“, sum, " 평균=“, avg) Advanced Broadcasting & Communications Lab. 12
세계로 미래로 power PNU 합계(sum)와 평균(average) 구하기 • 파일에서 값을 읽어서 배열 (array)에 넣는다. iarr = [0 for i in range(0, 100 + 1)] file 1 = open("while-sort-in 11. txt", "r") i=0 for line in file 1: i=i+1 iarr [i] = int(line) print ("i=", i, ": ", iarr[i]) numints = i print (numints, " 개의 수를 읽었습니다“) Advanced Broadcasting & Communications Lab. 13
세계로 미래로 power PNU 최대 값(max)과 최소 값(min) 구하기 count = 0 # 파일에 수가 1개 이상 있다고 가정 max_val = -1 # 파일에 있는 수가 양이라 가정 file 1 = open("max-in 12. txt" , "r") for line in file 1: num_read = int(line) count = count + 1 if (num_read > max_val): max_val = num_read file 1. close() print ("주어진 수", count, "개 중 최대", max_val) Advanced Broadcasting & Communications Lab. 15
세계로 미래로 power PNU 최대 값(max)과 최소 값(min) 구하기 for line in file 1: # line is a string var. num_read = int(line) count = count + 1 if (num_read > max_val): max_val = num_read file 1. close() if (count == 0): print ("주어진 수가 없어 최대값 찾을 수 없음“) else: print ("주어진 수 ", count, " 개 가운데 최대인 수 = ", max_val) Advanced Broadcasting & Communications Lab. 17
세계로 미래로 power PNU 최대 값(max)과 최소 값(min) 구하기 • 파일에 있는 모든 수 가운데 최대인 수를 찾되, read를 한 군데에 서만 한다 (두 군데가 아님) count = 0 file 1 = open("max-in 14. txt" , "r") for line in file 1: # line is a string var. num_read = int(line) count = count + 1 if (count == 1): #처음에 읽은 값을 최대값으로 max_val = num_read Advanced Broadcasting & Communications Lab. 18
세계로 미래로 power PNU 최대 값(max)과 최소 값(min) 구하기 • 둘째 값부터는 그 전까지의 최대값과 견주어서, 최대값이 바뀔 지 확인. elif (num_read > max_val): max_val = num_read else: pass # 할 일이 없음 file 1. close() Advanced Broadcasting & Communications Lab. 19
세계로 미래로 power PNU 최대 값(max)과 최소 값(min) 구하기 file 1 = open ("max-in 15. txt" , "r") for line in file 1: # line is a string var. num_read = int(line) count = count + 1 if (count == 1): max_val = num_read num_occ_max_val = 1 # 둘째 값부터는 그 전까지의 최대값과 견주어서, 최대값이 바뀔지 확인. elif (num_read > max_val): Advanced Broadcasting & Communications Lab. 21
세계로 미래로 power PNU 최대 값(max)과 최소 값(min) 구하기 max_val = num_read num_occ_max_val = 1 elif (num_read == max_val): # 회수 1 올라감 # max_val = num_read 안 바뀜 num_occ_max_val = num_occ_max_val + 1 else: pass # 할 일이 없음 print ("주어진 수 ", count, " 개 가운데 최대인 수 = ", max_val, "(", num_occ_max_val, " 번 나옴“) file 1. close() Advanced Broadcasting & Communications Lab. 22
세계로 미래로 power PNU 최대 값(max)과 최소 값(min) 구하기 for line in file 1: # line is a string var. num_read = int(line) count = count + 1 if (num_read > max_val): max_val = num_read ==> if (num_read < min_val): min_val = num_read Advanced Broadcasting & Communications Lab. 24
세계로 미래로 power PNU 파일 입출력 주의사항 - "textfile 1. txt"에서 실수를 바로 알 수 있다. Advanced Broadcasting & Communications Lab. 28
- Pusan national university uniform
- Outlook pnu
- Pnu point
- Ken proportioning system
- Cast of spring, summer, fall, winter... and spring
- Spring summer autumn winter dates
- Active power reactive power apparent power
- Seoul national university medical school
- Tanzania national nutrition survey 2020
- National core standards in health
- Cdha hotel discounts
- National dental hygienist week 2019
- Oxford university press answer
- Bucks new university ranking
- Decreto 1330 de 2019 power point
- Http://space-facts.com/the-moon/
- Big spring school district
- North spring primary school student care
- West spring secondary school
- Big spring school district
- Capri spring school
- Coral spring middle school
- 2019 virginia tech high school programming contest
- School workforce census 2019
- Cern high school program
- Alpbach summer school 2019
- National unification and the national state
- Chernivtsi university ukraine
- Kyiv national university of culture and arts
- National university of tainan
- National university polytechnic institute
- Donetsk national technical university