def exampleResult(s1, s2, s3, s4, s5):
passAvgScore = 60; limitScore = 40
def getTotal():
totalScore = s1 + s2 + s3 + s4 + s5
print(f'총점: {totalScore}')
return totalScore
def getAverage():
avg = getTotal() / 5
print(f'평균: {avg}')
return avg
def printPassOrFail():
print(f'{s1}: pass') if s1 >= limitScore else print (f'{s1}: fail')
print(f'{s2}: pass') if s2 >= limitScore else print (f'{s2}: fail')
print(f'{s3}: pass') if s3 >= limitScore else print (f'{s3}: fail')
print(f'{s4}: pass') if s4 >= limitScore else print (f'{s4}: fail')
print(f'{s5}: pass') if s5 >= limitScore else print (f'{s5}: fail')
def printFinalPassOrFail():
if getAverage() >= passAvgScore:
if s1 >= limitScore and s2 >= limitScore and s3 >= limitScore and s4 >= limitScore and s5 >= limitScore:
print('Final Pass!')
else:
print('Final Fail!')
else:
print('Final Fail')
getAverage()
printPassOrFail()
printFinalPassOrFail()
import module as m
if __name__ == '__main__':
sub1 = int(input('과목 1 점수 입력:'))
sub2 = int(input('과목 1 점수 입력:'))
sub3 = int(input('과목 1 점수 입력:'))
sub4 = int(input('과목 1 점수 입력:'))
sub5 = int(input('과목 1 점수 입력:'))
m.exampleResult(sub1, sub2, sub3, sub4, sub5)
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, int(totalPrice)]
def formatedNumber(n):
return format(n, ',')
import discount as dc
if __name__ == '__main__':
flag = True
gs = []
while flag:
selectNumber = int(input('1.구매, 2. 종료'))
if selectNumber == 1:
goods_price = int(input('상품 가격 입력: '))
gs.append(goods_price)
elif selectNumber == 2:
result = dc.calculatorTotalPrice(gs)
flag = False
print(f'할인율: {result[0]}')
print(f'합계: {dc.formatedNumber(result[1])}원')
import random
#사용자 입력번호 저장, 난수입력, 일치하는 숫자 목록도 있어야 함
userNums = []; randNums = []; collNums = []
randBonusNum = 0
def setUserNums(ns): #사용자 입력한 번호들을 매개변수로 해서 대입되도록
global userNums
userNums = ns
def getUserNums():
return userNums
def setRandNums():
global randNums
randNums = random.sample(range(1, 46), 6)
def getRandNums():
return randNums
def setBonusNum():
global randBonusNum
while True:
randBonusNum = random.randint(1, 45)
if randBonusNum not in randNums:
break
def getBonusNum():
return randBonusNum
def lottoResult():
global userNums
global randNums
global collNums
collNums = []
for un in userNums:
if un in randNums:
collNums.append(un)
if len(collNums) == 6:
print('1등 당첨')
print(f'번호: {collNums}')
elif len(collNums) == 5 and (randBonusNum in userNums):
print('2등 당첨')
print(f'번호: {collNums}, 보너스 번호: {randBonusNum}')
elif len(collNums) == 5:
print('3등 당첨')
print(f'번호: {collNums}')
elif len(collNums) == 4:
print('4등 당첨')
print(f'번호: {collNums}')
elif len(collNums) == 3:
print('5등 당첨')
print(f'번호: {collNums}')
else:
print('다음기회에')
print(f'기계번호: {randNums}')
print(f'보너스번호: {randBonusNum}')
print(f'선택번호: {userNums}')
print(f'일치번호: {collNums}')
def startLotto():
n1 = int(input('번호(1~45) 입력:'))
n2 = int(input('번호(1~45) 입력:'))
n3 = int(input('번호(1~45) 입력:'))
n4 = int(input('번호(1~45) 입력:'))
n5 = int(input('번호(1~45) 입력:'))
n6 = int(input('번호(1~45) 입력:'))
selectNums = [n1, n2, n3, n4, n5, n6]
setUserNums(selectNums)
setRandNums()
setBonusNum()
lottoResult()
import lotto as lt
lt.startLotto()
1.
def getPermutationCnt(n, r, logPrint = True): #경우의 수만 구함.
result = 1
for n in range(n, (n-r), -1):
if logPrint: print('n: {}'.format(n))
result = result * n
return result
from itertools import permutations
2.
def getPermutations(ns, r): #경우의수를 눈으로 볼 수 있게 해줌.
pList = list(permutations(ns, r))
print(f'{len(ns)}P{r} 개수: {len(pList)}')
for n in permutations(ns, r):
print(n, end='')
1.
import permutation as pt
numN = int(input('numN 입력:'))
numR = int(input('numR 입력:'))
print(f'{numN}P{numR}: {pt.getPermutationCnt(numN, numR, logPrint = False)}')
2.
listVar = [1, 2, 3, 4, 5, 6, 7, 8]
rVar = 3 #3개씩 뽑아냄
pt.getPermutations(listVar, rVar)
순서는 상관 없음
1.
def getCombinationCnt(n, r, logPrint = True): #매개값 보고싶을 때
#조합 = nPr / R!
resultP = 1 #순열 #곱셈이 들어가기 때문에 초기값 1로
resultR = 1 #R 팩토리얼
resultC = 1 #최종 조합 값
for n in range(n, (n-r), -1): #순열
resultP = resultP * n
if logPrint: print(f'resultP: {resultP}')
for n in range(r, 0, -1): #r부터 1까지,
resultR = resultR * n
if logPrint: print(f'resultR: {resultR}')
resultC = int(resultP / resultR)
if logPrint: print(f'resultC: {resultC}')
return resultC
2.
from itertools import combinations
def getCombinations(ns, r):
cList = list(combinations(ns, r))
print(f'{len(ns)}C{r}: {len(cList)}')
for n in combinations(ns, r):
print(n, end=',')
1.
import combination as ct
numN = int(input('numN 입력: '))
numR = int(input('numR 입력: '))
ct.getCombinationCnt(numN, numR)
print(f'{numN}C{numR}: {ct.getCombinationCnt(numN, numR, logPrint=False)}')
2.
listVar = [1, 2, 3, 4, 5, 6, 7, 8]
rVar = 3
ct.getCombinations(listVar, rVar)
income = 0
waterPrice = 0; electricPrice = 0; gasPrice = 0
#변수의 값 설정하는 함수
def setIncome(ic):
global income
income = ic
#변수의 값 얻어오는 변수
def getIncome():
return income
def setWaterPrice(wp):
global waterPrice
waterPrice = wp
def getWaterPrice():
return waterPrice
def setElectricPrice(ep):
global electricPrice
electricPrice = ep
def getElectricPrice():
return electricPrice
def setGasPrice(gp):
global gasPrice
gasPrice = gp
def getGasPrice():
return gasPrice
def getUtilityBill():
result = waterPrice + electricPrice + gasPrice
return result
def getUtilityBillRate():
result = getUtilityBill() / getIncome() * 100
return result
def formatedNumber(n):
return format(n, ',')
import utilityBill as ub
inputIncome = int(input('수입 입력: '))
ub.setIncome(inputIncome)
inputWaterPrice = int(input('수도요금 입력: '))
ub.setWaterPrice(inputWaterPrice)
inputElectricPrice = int(input('전기요금 입력: '))
ub.setElectricPrice(inputElectricPrice)
inputGasPrice = int(input('가스요금 입력: '))
ub.setGasPrice(inputGasPrice)
print(f'공과금: {ub.formatedNumber(ub.getUtilityBill())}원')
print(f'수입 대비 공과금 비율: {ub.getUtilityBillRate()}%')
-->
수입 입력: 3000000
수도요금 입력: 15000
전기요금 입력: 17500
가스요금 입력: 125000
공과금: 157,500원
수입 대비 공과금 비율: 5.25%
from arithmetic import basic_operator as bo
from arithmetic import developer_operator as do
from shape import circle_area as ca
from shape import triangle_square_area as tsa
inputNumber1 = float(input('숫자1 입력: '))
inputNumber2 = float(input('숫자2 입력: '))
print(f'{inputNumber1} + {inputNumber2} = {bo.add(inputNumber1, inputNumber2)}')
print(f'{inputNumber1} - {inputNumber2} = {bo.sub(inputNumber1, inputNumber2)}')
print(f'{inputNumber1} * {inputNumber2} = {bo.mul(inputNumber1, inputNumber2)}')
print(f'{inputNumber1} / {inputNumber2} = {bo.div(inputNumber1, inputNumber2)}')
print(f'{inputNumber1} % {inputNumber2} = {do.mod(inputNumber1, inputNumber2)}')
print(f'{inputNumber1} // {inputNumber2} = {do.flo(inputNumber1, inputNumber2)}')
print(f'{inputNumber1} ** {inputNumber2} = {do.exp(inputNumber1, inputNumber2)}')
inputWidth = float(input('가로 길이 입력: '))
inputHeight = float(input('세로 길이 입력: '))
print(f'삼각형 넓이: {tsa.calTriangleArea(inputWidth, inputHeight)}')
print(f'사각형 넓이: {tsa.calSquareArea(inputWidth, inputHeight)}')
inputRadius = float(input('반지름 입력: '))
print(f'원의 넓이: {ca.calCircleArea(inputRadius)}')