import math
n = int(input('numN입력'))
r = int(input('numR입력'))
def calculate(n, r):
result = math.factorial(n)/math.factorial(n-r)
return result
print(f'{n}P{r}결과 :{calculate(n, r)}')
순열 계산식으로 하면되긴하느데ㅔ..
순열 식을 몰른다구요 흑
> 모듈
import math
def calculC(n, r):
result = print(math.factorial(n)/math.factorial(n-r)*math.factorial(r))
return result
>실행파일
import example
n = int(input('n입력'))
r = int(input('r입력'))
example.calculC(n, r)
순열 조합 모듈이 위와 같으니까... 모듈에 저렇게 넣으면 될 줄 알았다? 그런데 안되네... ㅠ 너무 어려워잉 포기
>모듈
def outcomeCal(income, water, elec, gas) :
outcomeTotal = water+elec+gas
outcomeRate = outcomeTotal/income*100
result = print('공과금 : {}원\n'
'공과금 비율 : {}%'.format(format(outcomeTotal, ','), outcomeRate))
return result
>실행파일
import example
income = int(input('수입입력'))
water = int(input('수도 요금 입력'))
elec = int(input('전기 요금 입력'))
gas = int(input('가스 요금 입력'))
example.outcomeCal(income, water, elec, gas)
> 모듈
def basicoperator(num1, num2):
add = num1+num2
minus = num1-num2
multiple = num1*num2
div = num1/num2
result = print(f'{num1} +{num2} = {add}\n'
f'{num1} -{num2} = {minus}\n'
f'{num1} *{num2} = {multiple}\n'
f'{num1} /{num2} = {div}')
return result
def devloperoperator(num1, num2) :
mod = num1 % num2
floordiv = num1 // num2
multimulti = num1 ** num2
result = print(f'{num1} %{num2} = {mod}\n'
f'{num1} //{num2} = {floordiv}\n'
f'{num1} **{num2} = {multimulti}')
return result
>실행 파일
import example
num1 = float(input('숫자1 입력'))
num2 = float(input('숫자2 입력'))
example.basicoperator(num1, num2)
example.devloperoperator(num1, num2)
> 모듈
class Member :
def __init__(self, id, pw):
self.id = id
self.pw = pw
class MemberRegistory:
def __init__(self):
self.members = {}
def addMember(self, m):
self.members[m.id]=m.pw
def loginMember(self, id, pw):
ismember = id in self.members
if ismember and self.members[id] == pw:
print(f'{id}: Log-in success!!')
else:
print(f'{id} : Log-in Fail!')
def deletMember(self, id, pw):
del self.members[id]
def printMember(self):
for content in self.members.keys():
print(f'ID : {content}')
print(f'pw : {self.members[content]}')
>실행파일
import test as t
memberLists = t.MemberRegistory()
for i in range(3) :
Id = input('아이디 입력 :')
Pw = input('비밀번호 입력 :')
memberList =t.Member(Id, Pw)
memberLists.addMember(memberList)
memberLists.printMember()
memberLists.loginMember('dhdustn960','xkqlek1004')
memberLists.loginMember('dhdustn96031','xkqlek1004!')
memberLists.loginMember('dhdustn960314','Xkqlek1004!')
memberLists.deletMember('dhdustn960','xkqlek1004')
memberLists.printMember()
아앙 어려워잉
class NormalTV :
def __init__(self, inch, color, resoution, samrtTV, aiTV):
self.inch = inch
self.color = color
self.resoution = resoution
self.samrtTV = samrtTV
self.aiTV = aiTV
def turnon(self):
pass
def turnOff(self):
pass
def printTVinfo(self):
print(f'inch = {self.inch}')
print(f'color = {self.color}')
print(f'resoution = {self.resoution}')
print(f'samrtTV = {self.samrtTV}')
print(f'aiTV = {self.aiTV}')
class Tv4k(NormalTV) :
def __init__(self,inch, color, resoution):
super().__init__(inch, color, resoution)
def setSamrtTV(self):
pass
class Tv8k(NormalTV) :
def __init__(self, inch, color, resoution):
super().__init__(inch, color, resoution)
def setSmartTV(self):
pass
def SerAiTV(self):
pass
위에서 내용 받아서도 init하고 어떤거 받아서 여기서 바꾸는지 inch, color, resoution쓰고,
아래로 super().init(받은 변수들) 했어야하는군... ㅠ
https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=n2ll_&logNo=221442949008
class Book :
def __init__(self, name, price, isbn):
self.name=name
self.price=price
self.isbn=isbn
class BookRepository(Book):
def __init__(self, bDic):
self.bDic = {}
def registBook(self,b):
self.bDic[b.isbn] = b
def printBooksInfo(self):
for isbn in self.bDic.keys():
b = self.bDic[isbn]
def removeBook(self,isbn):
del self.bDic[isbn]
`````
어렵다 어려워~