#할인
def calculatorTotalPrice(gs):
if len(gs) <=0:
print('구매상품이 없습니다.')
return
rate = 25
totalPrice = 0
rates = {1:5, 2:10, 3:15, 4:20}
if len(gs) in rates:
rate = rates[len(gs)]
for g in gs:
totalPrice += g * (1 - rate * 0.01)
return[rate, format(int(totalPrice),',')+'원']
실행부
import discount as dc
if __name__ =='__main__' :
flag = True
gs = []
while flag:
seletNumber = int(input('1.구매, 2.종료:'))
if seletNumber == 1:
goods_price = int(input('상품가격 : '))
gs.append(goods_price)
else :
result = dc.calculatorTotalPrice(gs)
flag = False
print(f'할인율:{result[0]}')
print(f'합계:{result[1]}')
#공과금대비급여
r = 0
w = 0
e = 0
g = 0
def totalBill(w, e, g):
totalBill = w + e + g
return totalBill
def result(r, w, e, g):
result = float((w + e + g) / r * 100)
return result
실행부
import revenue as rv
revenue = int(input('수입입력: '))
water = int(input('수도요금 입력: '))
elec = int(input('전기요금 입력: '))
gas = int(input('가스요금 입력: '))
print(f'공과금: {rv.totalBill(water,elec,gas)}원')
print(f'공과금비율: {rv.result(revenue,water,elec,gas)}%')
class NormalTv:
def __init__(self, i=32, c='black', r='full-HD'):
self.inch = i
self.color = c
self.resolution = r
self.smartTV = 'off'
self.aiTV = 'off'
def turnOn(self):
print('TV Power On!')
def turnOff(self):
print('TV Turn Off!')
def printTvInfo(self):
print(f'inch: {self.inch}')
print(f'color: {self.color}')
print(f'resolution: {self.resolution}')
print(f'smartTV: {self.smartTV}')
print(f'aiTV: {self.aiTV}')
class Tv4k(NormalTv):
def __init__(self,i,c,r='4k'):
super().__init__(i,c,r)
def setSmartTv(self,s):
self.smartTv = s
class Tv8k(NormalTv):
def __init__(self,i,c,r='8k'):
super().__init__(i,c,r)
def setSmartTv(self,s):
self.smartTv = s
def setAiTv(self,a):
self.aiTv = a
실행부
import smartTV as st
my4KTv = st.Tv4k('65', 'silver', '4k')
my4KTv.setSmartTv('on')
my4KTv.turnOn()
my4KTv.printTvInfo()
my4KTv.turnOff()
friendKTv = st.Tv4k('55', 'white', '4k')
friendKTv.setSmartTv('off')
friendKTv.turnOn()
friendKTv.printTvInfo()
friendKTv.turnOff()