[파이썬] 딕셔너리 활용법(초보입니다 ㅠ)
조회수 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()
-
(•́ ✖ •̀)
알 수 없는 사용자
-
댓글 입력