야마타노오로치

일본어학과 학생들의 Python 도전기

모두를 위한 Python 특화과정/20171047 김동훈

python 데이터 구조-2

프로비우스윽 2022. 7. 27. 15:34
# Use words.txt as the file name
fname = input("Input file name : ")
fh = open('words.txt')
for line in fh:
    line = line.rstrip()
    print(line.upper())

 

결과

 

# Use the file name mbox-short.txt as the file name
fname = input("Enter file name: ")
fh = open(fname)
abc=0
count=0
for line in fh:
    if not line.startswith("X-DSPAM-Confidence:"):
        continue
    line= line.split()
    line=line[1]
    abc+=float(line)
    count+=1
    #print(abc)
print('Average spam confidence:',abc/count)

결과