class person:
def __init__(self, age, height, weight):
self.age=age
self.height=height
self.weight=weight
print("이 사람은 {0}살이고, 키는 {1}cm이며, 몸무게는 {2}kg입니다".format(self.age, self.height, self.weight))
chulsu=person(23,182,73)
younghee=person(23,166,50)
chulsu.crying =True
위 코드에서 person의 인자는 1개가 추가되어 총 4개이다.
맞으면 o, 틀리면 x 표시하시오. X
# 이론 문제 1-2 [5점]
class joker:
def laugh(self):
print('Haahahahahaa')
chulsu =joker()
chulsu.laugh()
실행 시 철수가 웃습니다.
위 코드가 맞으면 o, 틀리면 x 표시한 후 고치시오. O
# 이론 문제 1-3 [5점]
class StudentUnit:
def __init__(self, name, score):
self.name = name
self.score = score
def subject(self, title):
print("{0} 학생의 {1} 과목 점수는 {2} 점 입니다.".format(self.name, title, self.score))
student = StudentUnit("짱구", 35)
student.subject("수학")
위 코드를 실행하면 '짱구 학생의 수학 과목 점수는 35 점 입니다.'가 출력된다.
맞으면 o, 틀리면 x 표시한 후 고치시오. X
# 이론 문제 1-4 [5점]
1.
class Unit:
def __init__(self,name,station):
self.name = name
self.station = station
def time(self,time):
print("{0}은 {1}에 {2}시에 도착합니다.".format(self.name,self.station,time))
subway = Unit("7호선","어린이대공원역")
subway.time(4)
2.
class Unit:
def __init__(self,name,station):
self.name = name
self.station = station
def time(self,time):
self.time = time
print("{0}은 {1}에 {2}시에 도착합니다.".format(self.name,self.station,self.time))
subway = Unit("7호선","어린이대공원역")
subway.time(4)
1번과 2번 코드의 출력 결과는 같다.
맞으면 o, 틀리면 x 표시한 후 고치시오. X
# 이론 문제 2-1 [8점]
class Menu:
def __init__(self, name, price):
self.name = name
self.price = price
class Menu_Size(Menu):
def __init__(self, name, size, price):
super().__init__(name, price) # 부모 클래스의 생성자를 호출하여 name과 price 초기화
self.size = size
def Order(self, number):
print("{0} {1}개 {2}사이즈로 주문.".format(self.name, number, self.size))
def Price(self):
print("{0}원 입니다.".format(self.price))
ice_americano = Menu_Size("아이스아메리카노", "tall", 5000)
ice_americano.Order(2)
ice_americano.Price()
# 이론 문제 2-2 [6점]
class Unit:
def __init__(self,name,money):
self.name = name
self.money = money
class SadUnit(Unit):
def __init__(self,name,money,location):
Unit.__init__(self,name,money)
self.location = location
def earn(self,debt):
print("{0}는 {1}에서 {2}원을 벌었지만 {3}원의 빚이 있었다.".format(self.name,self.location,self.money,debt))
jaeha = SadUnit("재하", 1000, "롯데리아")
jaeha.earn(2000)
위의 코드를 <재하는 롯데리아에서 1000원을 벌었지만 2000원의 빚이 있었다.> 가 출력되도록 코드를 추가하여 마무리하시오.
# 이론 문제 2-3 [6점]
class Person:
def greeting(self):
print('안녕하세요!!')
class University:
def manage_credit(self):
print('시험공부 엉엉')
class Undergraduate(Person, University):
def study(self):
print('공부하자 공부')
chulsu = Undergraduate()
chulsu.greeting()
chulsu.manage_credit()
chulsu.study()
# 이론 문제 2-4 [5점]
기존의 매소드를 불러와 사용하는 것을 메소드 오버라이딩이라 한다.
맞으면 o, 틀리면 x 표시하시오. xxxx
# 이론 문제 2-5 [5점]
class Unit:
def __init__(self, name, hp):
self.name = name
self.hp = hp
class DamagedUnit(Unit):
def __init__(self, name, hp):
super().__init__(name, hp)
print("{} 유닛이 생성되었습니다.".format(self.name))
def damaged(self, damage):
self.hp -= damage
if self.hp <= 0:
print("{}는 파괴되었습니다.".format(self.name))
else:
print("{}이 {}만큼 데미지를 입었습니다. \\n{}의 현재 체력은 {}입니다.".format(self.name, damage, self.name, self.hp))
archer = DamagedUnit("아처", 100)
archer.damaged(20)