[파이썬] 딕셔너리 활용법(초보입니다 ㅠ)

조회수 976회

이미지

infile=open("python_07_04.txt",'w')

subject="Q"
score="1"

test_dict={subject:score}

while(subject!="Q"):
     subject=input()
while(score!="0"):
     score=input()

infile.write(subject+" : "+score)
infile.write("total = "+score)
infile.write("average = "+float(score/3))

infile.close()
outfile=open("python_07_04.txt",'r')
text=outfile.read()
print(text)
outfile.close()

위 사진의 코딩을 하였으나 하나 부터 열까지 진행이 안되네요 ㅠㅠ 딕셔너리 설정을 어떻게 하는지 조언 부탁드려요 감사합니다.

  • (•́ ✖ •̀)
    알 수 없는 사용자

1 답변

  • infile=open("python_07_04.txt",'w')
    
    test_dict={'Q':1}
    
    while(test_dict['Q']==1):
        subject=input()
        score=input()
        test_dict[subject]=score
    
    
    test_dict.pop('Q',None)
    total = 0
    
    for a in test_dict:
        infile.write(str(a+' : '+test_dict[a]+'\n'))
        total+=float(test_dict[a])
    
    infile.write(str("total = {}\n".format(total)))
    infile.write(str('avg = {}\n'.format(total/(len(test_dict)))))
    
    infile.close()
    outfile=open("python_07_04.txt",'r')
    text=outfile.read()
    print(text)
    
    outfile.close()
    
    • (•́ ✖ •̀)
      알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)