꾸엥 견제된다...
print("Python" , "Java", sep=",", end="?")
print("무엇이 더 재밌을까요?") #맨 마지막 개행이엇는데 물음표로
#결과 Python,Java?무엇이 더 재밌을까요?
import sys
print("Python", "Java", file=sys.stdout) #표준출력으로 문장이 찍힘
print("Python", "Java", file=sys.stderr) #표준 에러로 처리
scores={"수학":0,"영어":50, "코딩":100}
for subject, score in scores.items(): #item은 키와 밸류 쌍으로
print(subject, score)
answer=input("아무 값이 나 입력하세요ㅣ")
answer=10
print(type(answer))
print("입력 답" + answer + "입니다")
#빈 자리는 빈공간으로 두고, 오른쪽 정렬을 하되, 총 10자리 공간 확보
prnit("{0:>10}".format(500))
#양수일 땐 +로 표시, 음수일땐 -로 표시
prnit("{0:>+10}".format(500))
prnit("{0:>+10}".format(-500))
#왼쪽 정렬, 빈칸 _로 채우기
prnit("{0:_<10}".format(500))
#3자리마다 콤마로 찍어주기
prnit("{0:,}".format(100000000000000))
#3자리마다 콤마로 찍어주기, +- 부호도 붙이기
prnit("{0:,}".format(100000000000000))
prnit("{0:+,}".format(-100000000000000))
#3자리 마다 콤마를 찍어주기, 부호도 붙이고 자릿수 확보
#돈이 많으면 행복하니깐 빈자리는 ^로 채워주기
print("{0:^<+30,}".format(10000000000000)
#소수점 출력
print("{0:f}".format(5/3))
#소수점 특정 자리수 까지만 표시 (소수점 3째 자리에서 반올림)
print("{0:.2f}".format(5/3))
score_file=open("score.txt", "w", encoding="utf8")
print("수학:0",file=score_file)
print("영어:50", file=score_file)
score_file.close()
# score_file=open("score.txt", "w", encoding="utf8") #쓰기
# print("수학:0",file=score_file)
# print("영어:50", file=score_file)
# score_file.close()
# score_file=open("score.txt", "a", encoding="utf8") #추기
# score_file.write("과학:80")
# score_file.write("\n코딩:100")
score_file=open("score.txt","r",encoding="utf8") #내용 불러오기
print(score_file.read())
score_file.close()
#한 줄씩 읽어오기 커서는 자동으로 다음라인
score_file=open("score.txt","r", encoding="utf8")
print(score_file.readline()) #줄 별로 읽기, 한 줄 읽고 커서는 다음 줄로 이동
print(score_file.readline())
print(score_file.readline())
print(score_file.readline())
score_file.close()
score_file=open("score.txt", "r" , encoding="utf8")
while True:
line = score_file.readline()
if not line:
break
print(line, end="") #줄 바꿈 없애기
score_file.close()
score_file=open("score.txt", "r" , encoding="utf8")
lines=score_file.readlines() #list 형태로 저장
for line in lines:
print(line, end="")
score_file.close()
#pickle
#프로그램 상에서 사용하는 데이터를 파일 형태로 저장함
import pickle
profile_file=open("profile.pickle", "wb") #"wb" 는 쓰기
profile={"이름:": "김민졍","나이":30, "취미": ["축구","골프","코딩"]}
print(profile)
pickle.dump(profile, profile_file) #profile에 있는 정보를 file에 저장
profile_file.close()
#가져와보자
profile_file=open("profile.pickle","rb") #읽기b는 바이너리
profile=pickle.load(profile_file) #file에 있는 정보를 profile에 불러오기
print(profile)
profile_file.close()
#with 활용해서 간단하게 파일 입출력
#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())
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())
퀴즈
print("{0:f}".format(5/3))
#소수점 특정 자리수 까지만 표시 (소수점 3째 자리에서 반올림)
print("{0:.2f}".format(5/3))
score_file=open("score.txt", "w", encoding="utf8")
print("수학:0",file=score_file)
print("영어:50", file=score_file)
score_file.close()
# score_file=open("score.txt", "w", encoding="utf8") #쓰기
# print("수학:0",file=score_file)
# print("영어:50", file=score_file)
# score_file.close()
# score_file=open("score.txt", "a", encoding="utf8") #추기
# score_file.write("과학:80")
# score_file.write("\n코딩:100")
score_file=open("score.txt","r",encoding="utf8") #내용 불러오기
print(score_file.read())
score_file.close()
#한 줄씩 읽어오기 커서는 자동으로 다음라인
score_file=open("score.txt","r", encoding="utf8")
print(score_file.readline()) #줄 별로 읽기, 한 줄 읽고 커서는 다음 줄로 이동
print(score_file.readline())
print(score_file.readline())
print(score_file.readline())
score_file.close()
score_file=open("score.txt", "r" , encoding="utf8")
while True:
line = score_file.readline()
if not line:
break
print(line, end="") #줄 바꿈 없애기
score_file.close()
score_file=open("score.txt", "r" , encoding="utf8")
lines=score_file.readlines() #list 형태로 저장
for line in lines:
print(line, end="")
score_file.close()
#pickle
#프로그램 상에서 사용하는 데이터를 파일 형태로 저장함
import pickle
profile_file=open("profile.pickle", "wb") #"wb" 는 쓰기
profile={"이름:": "김민졍","나이":30, "취미": ["축구","골프","코딩"]}
print(profile)
pickle.dump(profile, profile_file) #profile에 있는 정보를 file에 저장
profile_file.close()
#가져와보자
profile_file=open("profile.pickle","rb") #읽기b는 바이너리
profile=pickle.load(profile_file) #file에 있는 정보를 profile에 불러오기
print(profile)
profile_file.close()
#with 활용해서 간단하게 파일 입출력
#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())
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())
퀴즈
for i in range(1, 51):
with open(str(i)+ "주차.txt", "w", encoding="utf8") as report_file:
report_file.write("-{0} 주차 주간 보고서 - ".format(i))
report_file.write("\n부서 : ")
report_file.write("\이름 : ")
report_file.write("\업무 요약 : ")
#마린:공격 유닛, 공격, 총을 쏠 수 있음
name="마린" #유닛의 이름
hp=40 #유닛의 체력
damage=5 #유닛의 공격력
print("{0} 유닛이 생성되었습니다. ". format(name))
print("체력 {0}, 공격력 {1}\n".format(hp, damage))
#탱크 : 공격 유닛, 탱크, 포를 쏠 수 있는데 , 일반모드/시즈모드
tank_name="탱크2"
tank_hp = 150
tank_damage=35
print("{0} 유닛이 생성되었습니다.".format(tank_name))
print("체력 {0}, 공격력 {1}\n".format(tank_hp, tank_damage))
tank2_name="탱크"
tank2_hp = 150
tank2_damage=35
print("{0} 유닛이 생성되었습니다.".format(tank2_name))
print("체력 {0}, 공격력 {1}\n".format(tank2_hp, tank_damage))
def attack(name, location, damage):
print("{0} : {1}방향으로 적군을 공격합니다. [공격력{2}]".format(\
name, location, damage))
attack(name, "1시", damage)
attack(tank_name, "1시", tank_damage)
attack(tank2_name, "1시", tank_damage)
#class는 붕어빵 틀
class Unit:
def __init__(self, name, hp, damage): #필요한 값들 정의하기
self.name=name
self.hp=hp
self.damage=damage
print("{0} 유닛이 생성되었습니다.".format(self.name))
print("체력{0} , 공력력 {1}".format(self.hp, self.damage))
marine1=Unit("마린", 40 , 5)
marine2=Unit("마린", 40, 5)
tank=Unit("탱크", 150, 35)
'Programming > Python' 카테고리의 다른 글
파이썬 무료 강의 (활용편1) - 추억의 오락실 게임 만들기 (3시간) (2) | 2021.04.06 |
---|---|
인프런 파이썬 공부4 (완강) (2) | 2021.03.31 |
인프런 파이썬 공부2 (0) | 2021.03.27 |
인프런 파이썬 강의 (1) | 2021.03.27 |
[이코테]2. 그리디 & 구현 (0) | 2021.01.14 |