no image
[고1 프로그래밍] 2학기 2차 지필평가
# --[클래스]-- 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) shark.say() # --[파일]-- # f = open("새파일.txt", "w", encoding="utf-8") f.write("첫 번째 문장") f.write("\n두 번째 문장") f.write("\n세 번째 문장") f.close() # f = open("새파일.txt", "r", encoding="utf-8") line1 = f.readline() # 첫 번째 줄 읽기 print(line1) ..
2023.12.20
no image
[고1 프로그래밍] 12 - (1)
class SoldOutError(Exception): pass chicken = 10 waiting = 1 # 틀 안에는 현재 만석, 대기번호 1부터 시작 while(True): try: print("[남은 치킨 : {0}]".format(chicken)) order = int(input("치킨 몇 마리 주문하시겠습니까?")) if order > chicken: # 남은 치킨보다 주문량이 많을때 print("재료가 부족합니다.") elif order
2023.12.04
no image
[고1 프로그래밍] 11 - (5)
class House: # 매물 초기화 def __init__(self, location, house_type, deal_type, price, completion_year): self.location = location self.house_type = house_type self.deal_type = deal_type self.price = price self.completion_year = completion_year # 매물 정보 표시 def show_detail(self): print(self.location, self.house_type, self.deal_type\ , self.price, self.completion_year) houses = [] house1 = House("강남", "아파..
2023.11.30
no image
[고1 프로그래밍] 11 - (4)
class Unit: def __init__(self): print("Unit 생성자") class Flyable: def __init__(self): print("Flyable 생성자") class FlyableUnit(Unit, Flyable): def __init__(self): #super().__init__() Unit.__init__(self) Flyable.__init__(self) # 드랍쉽 dropship = FlyableUnit() 나도코딩 - 스타크래프트 try: print("나누기 전용 계산기입니다.") num1 = int(input("첫 번째 숫자를 입력하세요 : ")) num2 = int(input("두 번째 숫자를 입력하세요 : ")) print("{0} / {1} = {2}"..
2023.11.20
no image
[고1 프로그래밍] 11 - (3)
# 일반 유닛 class Unit: def __init__(self, name, hp, speed): self.name = name self.hp = hp self.speed = speed def move(self, location): print("[지상 유닛 이동]") print("{0} : {1} 방향으로 이동합니다. [속도 : {2}]"\ .format(self.name, location, self.speed)) # 메딕 : 의무병(공격력 없음, 사람으로 된 유니싱 다쳤을 때 치료해주어 체력을 회복시켜 줌) # 공격 유닛 class AttackUnit(Unit): def __init__(self, name, hp, speed, damage): Unit.__init__(self, name, hp, s..
2023.11.15
no image
[고1 프로그래밍] 11 - (2)
# 일반 유닛 class Unit: def __init__(self, name, hp, speed): self.name = name self.hp = hp self.speed = speed def move(self, location): print("[지상 유닛 이동]") print("{0} : {1} 방향으로 이동합니다. [속도 : {2}]"\ .format(self.name, location, self.speed)) # 메딕 : 의무병(공격력 없음, 사람으로 된 유니싱 다쳤을 때 치료해주어 체력을 회복시켜 줌) # 공격 유닛 class AttackUnit(Unit): def __init__(self, name, hp, speed, damage): Unit.__init__(self, name, hp, s..
2023.11.13
no image
[고1 프로그래밍] 11 - (1)
# 일반 유닛 class Unit: def __init__(self, name, hp, speed): self.name = name self.hp = hp self.speed = speed def move(self, location): print("[지상 유닛 이동]") print("{0} : {1} 방향으로 이동합니다. [속도 : {2}]"\ .format(self.name, location, self.speed)) # 메딕 : 의무병(공격력 없음, 사람으로 된 유니싱 다쳤을 때 치료해주어 체력을 회복시켜 줌) # 공격 유닛 class AttackUnit(Unit): def __init__(self, name, hp, speed, damage): Unit.__init__(self, name, hp, s..
2023.11.08
no image
[고1 프로그래밍] 10 - (2)
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("강아지", 4) shark.say() wolf.say() dog.say() class Unit: def __init__(self, name, hp): self.name = name self.hp = hp class AttackUnit(Unit): def __init__(self, name, hp, damage): Unit.__init__(self, name, h..
2023.10.17
no image
[고1 프로그래밍] 10 - (1)
print("Python", "Java") print("Python" + "Java") print("Python", "Java", sep=".") print("Python", "Java", "JavaScript", sep=" vs ") print("Python", "Java", sep=", ", end="?") print("무엇이 더 재미있을까요?") for num in range(1, 21): print("대기번호 :" + (str(num).zfill(3))) print("{0: >+10}".format(500)) print("{0: >+10}".format(-500)) 피보나치 def fib(n): if n==0: return 0 if n==1: return 1 return fib(n-2) + fib..
2023.10.16