
개발사항 메일을 수신한 요일을 추출하여 출력 ("From" 이라는 문자열로 시작하는 라인의 세 번째 단어 추출) contents = open('mbox-short.txt') for line in contents : line = line.rstrip() wds = line.split() # 가디언패턴 적용 # 라인이 공백이거나 세 단어 미만이면 print(wds[2]) 부분에서 에러 발생 # wds 의 길이가 3 미만인 경우는 반복문의 처음으로 이동하여 에러 방지 if len(wds) < 3 or wds[0] != 'From' : continue print(wds[2]) contents.close() END

개발사항 사용자에게 입력받은 값의 평균을 구한다. done 이라는 문자열이 입력되기 전까지 숫자를 계속 입력받는다. done 이 입력되면 총합계 및 평균을 출력하고 프로그램을 종료한다. i_num = 0 f_tot = 0.0 while True : #무한루프를 돌며 사용자에게 값을 입력받는다. s_inputVal = input('Enter a number : ') if s_inputVal == 'done' : #입력값이 'done' 이면 평균값을 출력하고 프로그램 종료 break try: #연산을 위해 문자열을 실수형으로 형변환 f_inputVal = float(s_inputVal) except: #입력값이 숫자 또는 'done' 이 아니면 메세지 출력 후 다시 루프를 탄다. print('Invalid ..