no image
[고1 프로그래밍] 09 - (6)
#일반 유닛 class Unit: def __init__(self, name, hp): self.name = name self.hp = hp print("{0} 유닛이 생성되었습니다.".format(self.name)) print("체력 : {0}, 공격력 : {1}".format(self.hp, self.damage)) #공격 유닛 class AttackUnit: def __init__(self, name, hp, damage): self.name = name self.hp = hp self.damage = damage def attack(self, location): print("{0} : {1} 방향으로 적군을 공격합니다. [공격력 {2}]"\ .format(self.name, location, s..
2023.09.27
no image
[고1 프로그래밍] 09 - (5)
#일반 유닛 class Unit: def __init__(self, name, hp, damage): self.name = name self.hp = hp self.damge = damage # 공격 유닛 class AttackUnit: def __init__(self, name, hp, damage): self.name = name self.hp = hp self.damage = damage def attack(self, location): print("{0} : {1} 방향으로 적군을 공격합니다. [공격력 : {2}]"\ .format(self.name, location, self.damage)) def damaged(self, damage): print("{0} : {1} 데미지를 입었습니다.".f..
2023.09.25
no image
[고1 프로그래밍] 09 - (4)
class Monster: def __init__(self, name, age): self.name = name self.age = age def say(self): print(f"나는 {self.name}이고 {self.age}살이다.") shark = Monster("상어", 7) wolf = Monster("늑대", 5) dog = Monster("강아지", 3) cat = Monster("고양이", 1) shark.say() wolf.say() dog.say() cat.say() # 마린 : 공격 유닛, 군인, 총을 쏠 수 있음. name = "마린" hp = 40 damage = 5 print("{0} 유닛이 생성되었습니다.".format(name)) print("체력 {0}, 공격력 {1}\n..
2023.09.20
no image
[고1 프로그래밍] 09 - (3)
import pickle profile3_file = open("profile3.pickle", "wb") profile3 = {"이름":"박명수", "나이":30, "취미":["축구", "골프", "코딩"]} print(profile3) pickle.dump(profile3, profile3_file) profile3_file.close() # import pickle # profile3_file = open("profile3.pickle", "rb") # profile3 = pickle.load(profile3_file) # print(profile3) # profile3_file.close() import pickle with open("profile3.pickle", "rb") as profile..
2023.09.18
no image
[고1 프로그래밍] 09 - (2)
file = open("newfile.txt","w",encoding="utf-8") for i in range(1,11): data = "%d번째 입니다\n" % i file.write(data) # data를 파일객체(file)에 써라 file.close() file = open("newfile.txt","r",encoding="utf-8") line = file.readline() print(line) file.close() file = open("newfile.txt", "r", encoding="utf-8") while True: line = file.readline() if not line: break print(line, end="") file.close() file = open("newfi..
2023.09.13
no image
[고1 프로그래밍] 09 - (1)
f = open("newfile.txt", "w", encoding="utf-8") for i in range(1, 11): data = "%d번째 줄입니다.\n" %i f.write(data) f.close() # for i in range(1, 11): # data = "%d번째 줄입니다.\n" %i # print(data) # f = open("newfile.txt", "r", encoding="utf-8") # line = f.readline() # print(line) # f.close() # f = open("newfile.txt", "r", encoding="utf-8") # while True: # line = f.readline() # if not line: # break # print(..
2023.09.11
no image
[고1 프로그래밍] 08 - (1)
answer = input("아무 값이나 입력하세요.") print(type(answer)) print("입력하신 값은 " + answer + "입니다.") print("Python", "Java") print("Python" "Java") print("Python" + "Java") print("Python", "Java", sep=" , ") print("Python", "Java", "JavaScript", sep=" vs ") print("Python", "Java", sep=",", end="? ") print("무엇이 더 재미있을까요?") scores = {"수학":0,"영어":50,"코딩":100} for subject, score in scores.items(): #print(subject..
2023.08.30