스터디/파이썬 스터디 과제

[3팀 / 김은수] 8차시 파이썬 과제 - 객체 지향 프로그래밍

lyra8 2023. 5. 24. 09:26

1번

class Bit(object):
	def __init__(self):
		self.__password = 5678
	def set_password(self, new_pw):
		self.__password = **self.new_pw**
		print('Password changed')
	def get_password **self.new_pw**:
		print('Your password is :', self.__password)

coin = Bit()
coin.get_password()
coin.set_password(1234)
print(coin.__password)

 

2번

class Company:
	def __init__(self):
		self.work = True

self.name = 'Jane'
		self.gender = 'woman'
	def retire(self):
		self.work = False

class Employee(Company):
	def __init__(self, name, gender):
		super().__init__()
		self.name = **'Jane'**
		**'woman'** = gender
	def introduce(self):
		if self.work == True:
			print('I got a job at a company')
			print ('My name is', self.name)
			print('I am a', self.gender)
		**if self.work == Flase**
			print('I left the company')

em = Employee('james', 'man')
em.retire()
em.introduce()
Employee('james', 'man').introduce()

3번

class Person(object):
	def __init__(self, name):
		self.name = **name**

def language(self):
	**self.language=language**

class Earthling(Person):
	def language(self, language):
		return language

class Groot(Person):
	def language (self, language):
		return "I'm Groot!"

name = ['Hanbit', 'Dr.Strange', 'Groot']
country = ['Korea', 'USA', 'Galaxy']
language = ['Korean', 'English', 'Groot']

for idx, name in enumerate(name):
	if country[idx].upper() != 'GALAXY':
		person = Earthling(name)
		print(person.language(language[idx]))
	else:
		groot = Groot(name)
		print(groot.language(language [idx]))

4번

class SoccerPlayer(object):
	def __init__(self, name, position, back_number):
		**self.name = name**
		self.position = position
		self.back_number = back_number

	def change_back_number(self, back_number):
		**self.back_number = back_number**

mina = SoccerPlayer("mina", "MF", 10)
print("현재 선수 등번호는:", **mina.back_number** )
mina.change_back_number(5)