이론문제

다음 문장을 읽고 옳은지 틀린지 O,X로 표시한 후, 틀린 문장은 알맞게 고치시오. [10점]
[2점] 1. print("Python", end = "")후 다음 줄에 print("Java")를 입력하면 한 줄로 출력된다.    0
[2점] 2. 출력문을 정렬시키는 함수에는 ljust, rjust, zfill 등이 있다. x (애매)?? zfill은 0으로 채우는거아닌가?정렬이라고 하나?
[2점] 3. print("{0:-,}".format(5000000))을 입력하면 -5000000이 출력된다. x 세자리마다 콤마가 나옴
고친거---print("{0:-,}".format(5000000))을 입력하면 5,000,000이 출력된다.
[2점] 4. 소수점 둘째자리에서 반올림된 소수를 표현하고 싶으면 print("{0:.2f}".format(소수))를 하면된다. 0
[2점] 5. with함수를 사용하여 file을 다룰 때에는 마지막에 .close()를 사용하지 않아도 된다.  0

실습문제

import pickle
print("KOREA", "CHINA","JAPAN", sep=" vs ")

data ={"KOREA":33,"CHINA":180,"JAPAN":44}
for country,medal_count in data.items():
    print("{0: <6} : {1:03}".format(country,medal_count))
sep = ","
사이사이에 , 를 넣어준다

end = ""
줄바꿈 x

import sys
file = sys.stdout 표준출력
file = sys.stderr 표준에러

score = {"수학":0,"영어":50,"코딩":100}
for subject,score in score.items():
    print(subject.ljust(8),score)

.items() 는 변수 안에 있는 "" 와 숫자를 넣어줌
.ljust(숫자)는 앞에 변수 포함해서 숫자칸을 만들고 왼쪽 정렬
.rjust(숫자)는 앞에 변수 포함해서 숫자칸을 만들고 오른쪽 정렬

.zfill(숫자) 숫자 칸만큼 칸을 만들고 나머지는 0으로 채움

a = intput()
printf("하하" + a + "나나") 

print("{0: >10}".format(500))
나머지는 빈칸,> 는 오른쪽으로 정렬, 10칸 만들기
print("{0: >+10}".format(500))
+ 양수이면 +숫자 로 출력 음수이면 -숫자로 출력
print("{0: >-10}".format(-500))
마이너스일때만 -출력 +는 아님
print("{0:_<+10}".format(500))
나머지 _로 출력 <는 오른쪽 정렬,+ or - 숫자 로 출

print("{0:,}".format(1000000000))
세자리마다 ,표시 
print("{0:^<+30,}".format(100000000))
빈자리 ^, 왼쪽정렬, +,30칸, 3자리마다 콤마

print("{0:.2f}".format(5/3))
.2는 소수점 둘쨰자리까지

score_file =  open("score.txt","w",encoding = "utf8")
print("수학 : 0", file=score_file)
print("duddj : 50", file=score_file)
score_file.close()

score_file =  open("score.txt","w",encoding = "utf8")
score_file.write("과학 : 80")
score_file.write("\\n코딩 : 100")
score_file.close()

??????? 뭐지
score_file 은 변수
"w"는 쓴다.
"a" 는 뒤에 계속 쓰고 싶다.
"r" 은 읽는다.
score_file.close() 파일을 닫는다.
score_file.read() 모두읽는다
score_file.readline() 줄별로 읽는다

while True:
	line = score_file.readline()
	if not line :
		break
score_file.close()
줄의 개수를 모를떄 한줄씩 하다가 라인이 없으면 나감

lines = score_file.readlines() // list 형태로 저장
for line in lines:             // 한줄씩 line에 저장
	print(line,end="")
score_file.close()

import pickle
profile_file = open("profile.pickle","wb")
profile = {"이름":"박명수","나이":30, "취미":["축구","골프","코딩"]}
print(profile)
pickle.dump(profile,profile_file)
profile_file.close()

profile_file = open("profile.pickle","rb")
profile = pickle.load(profile_file)
print(profile)
profile_file.close()
?????????????????????????????????

with open("study.txt","w", encoding="utf8") as study_file:
    study_file.write("파이썬을열심히 공부하고 있어요")

with open("study.txt","r", encoding="utf8") as study_file:
    print(study_file.read())