Menu



Manage

Cord > Study_Python 전체 다운로드
Study_Python > make/11week.py Lines 71 | 1.7 KB
다운로드

                        # 11주차
import os #파일 생성할때는 필수

scores = {} #점수 딕셔너리 생성
kor = []
eng = []
math = []

i = int(0)

#파일열기
f = open("c:/Users/-/Desktop/py_Project/list.txt", 'w')

while True :
    #이름입력
    print("이름 입력창에 미입력시 종료됩니다.")
    name = input("이름을 입력하세요 : ").strip()
    if name == '' :
        break

    #점수입력
    print("점수를 입력해주세요")
    kor.append(input("국어점수 :").strip())
    eng.append(input("영어점수 :").strip())
    math.append(input("수학점수 :").strip())

    #딕셔너리 만들기
    scores[name] = [kor[i], eng[i], math[i]]

    i += 1

#반복문 종료 후, 결과 입력
i = 0
for name, step in scores.items() :
    data = f"{name}, {kor[i]}, {eng[i]}, {math[i]}\n"
    f.write(data)
    i += 1

f.close()

"""
#수업 방법

stuendts = []
while True :
    try:
        name = input("이름 :").strip()
        if not name : 
            break
        kor = int(input("국어 :").strip())
        eng = int(input("영어 :").strip())
        mat = int(input("수학 :").strip())
    
        stu = [name, string(kor), string(eng), string(mat)]
        students.append(stu)
    except:
        print("점수를 바르게 입력하세요.")
    
path_name = "c:/-/"
full_filename = path_name + "/list.txt"

if nont os.path.isdir(path_name) : #os모듈이 파일 체크해줌
    os.mkdir(path_name) #폴더가 없다면 폴더 생성
    
with open(full_filename, "w") as f:
    for stu in students :
        #stu -> ['name', 'kor', 'eng', 'mat'] => 'name, kor, eng, mat\n'
        ",".join(stu) + "\n"
        f.write(line)        
    
"""