

>모듈
from abc import *
class AbsDictionary(metaclass=ABCMeta):
    def __init__(self):
        self.wordDic = {}
    @abstractmethod
    def registWord(self, w1, w2):
        pass
    @abstractmethod
    def removeWord(self, w1):
        pass
    @abstractmethod
    def updateWord(self, w1, w2):
        pass
    @abstractmethod
    def searchWord(self, w1):
        pass
class KoreToEng(AbsDictionary) :
    def __init__(self):
        self.wordDic = {}
        super().__init__()
    def registWord(self, w1, w2):
        print(f'KoreaToEng : {w1} to {w2}')
        self.wordDic[w1] = w2
    def removeWord(self, w1):
        print(f'KoreaToEng remove: {w1}')
        del self.wordDic[w1]
    def updateWord(self, w1, w2):
        print(f'KoreaToEng update: {w1} to {w2}')
        self.wordDic[w1] = w2
    def searchWord(self, w1):
        print(f'KoreaToEng searchWord:{w1} is {self.wordDic[w1]}')
    def printWords(self):
        for words in self.wordDic :
            print(f'{words} : {self.wordDic[words]}')
>실행파일
import test
from test import  *
use = test.KoreToEng()
use.registWord('한국', 'Korea')
use.registWord('일본', 'Japan')
use.registWord('중국', 'China')
use.removeWord('일본')
use.updateWord('한국', "KOREA")
use.printWords()
use.searchWord('중국')

>모듈
import random
class Dice :
    def __init__(self):
        self.userNum = 0
        self.comNum = 0
    def setComNum(self):
        self.comNum = random.randint(1,6)
        print('컴퓨터가 주사위를 굴렸습니다.')
    def setUserNum(self):
        self.userNum = random.randint(1,6)
    def startGame(self):
        print(f'게임 시작!')
    def printResult(self):
        if self.comNum > self.userNum :
            print(f'컴퓨터 vs 유저 : {self.comNum} vs {self.userNum}  >> 컴퓨터 승!!' )
        elif self.comNum == self.userNum :
            print(f'컴퓨터 vs 유저 : {self.comNum} vs {self.userNum}  >> 무승부!!' )
        elif self.comNum < self.userNum :
            print(f'컴퓨터 vs 유저 : {self.comNum} vs {self.userNum}  >> 유저 승!!' )
>실행파일
from test import *
game = Dice()
game.startGame()
game.setComNum()
game.setUserNum()
game.printResult()
노답이라서
https://wikidocs.net/7036
이거로 대체함
class Stock :
    def __init__(self, name, code, PER, PBR, rate):
        self.name = name
        self.code = code
        self.PER = PER
        self.PBR = PBR
        self.rate = rate
    def set_name(self, name):
        self.name = name
    def set_code(self, code):
        self.code = code
    def get_name(self):
        print(f'name : {self.name}')
    def get_code(self):
        print(f'code : {self.code}')
    def set_per(self,PER):
        self.PER = PER
    def set_pbr(self,PBR):
        self.PBR = PBR
    def set_dividend(self,rate):
        self.rate = rate
thing = []
samsung = Stock("삼성전자", '005930', 15.79, 1.33, 2.83)
hundai = Stock("현대차", '005380', 8.70, 0.35, 4.27)
LG = Stock("LG전자", '066570', 317.34, 0.69, 1.37)
thing.append(samsung)
thing.append(hundai)
thing.append(LG)
for i in thing :
    print(i.code, i.PER)
import random
class Account :
    accountCount = 0
    def __init__(self, user, left):
        self.bank = 'SC은행'
        self.user = user
        num1 = random.randint(0,999)
        num2 = random.randint(0,99)
        num3 = random.randint(0,9999999)
        num1 = str(num1).zfill(3)
        num2 = str(num2).zfill(2)
        num3 = str(num1).zfill(6)
        self.code = num1+'-'+num2+'-'+num3
        self.left = left
        Account.accountCount += 1
        self.depositCount = 0
        self.deposit_history = []
    @classmethod
    def get_account_num(cls):
        print(cls.accountCount)
    def deposit(self, money):
        if money == 0 :
            print('입금은 최소 1원 이상만 가능')
        else:
            self.deposit_history.append(money)
            self.left += money
        self.depositCount +=1
        if self.depositCount >5 :
            self.left *= 1.01
    def withdraw(self, outmoney):
        if outmoney > self.left:
            print('출금은 계좌의 잔고 이상으로 출금할 수는 없습니다')
        else:
            self.left -= outmoney
    def display_info(self):
        print(f'bank : {self.bank}\n'
              f'name : {self.user}\n'
              f'code : {self.code}\n',
              'left : {}'.format(format(self.left, ',')))
    def deposit_history(self):
        for money in self.deposit_history:
            print(money)
kiki = Account('kiki',1000000)
kiki.deposit(100000)
kiki.deposit(10000)
kiki.deposit(1000)
kiki.deposit(100)
kiki.deposit(10)
kiki.deposit_history()
class Car:
    def __init__(self, tire, price, ):
        self.tire = tire
        self.price = price
    def info(self):
        print(f'tire : {self.tire}\n'
              f'price : {self.price}')
class RealCar(Car) :
    def __init__(self, tire, price):
        super().__init__(tire,price)
class Bicycle(Car) :
    def __init__(self, tire, price, workout):
        super().__init__(tire,price)
        self.workout = workout
    def BicycleInfo(self):
        super().info()
        print(f'workout : {self.workout}')
car = Bicycle(4,1000,'t')
car.BicycleInfo()