💬 오늘의 공부시간 PM 11:00~ AM 01:05

몸이 아직 회복중인지 정말이지 집중하기가 힘들다.
머리에 안들어오는 중급파이썬도 내 건강에 영향을 미치는 것인지
머리랑 어깨가 엄청 무겁다. ㅠㅠ


🔥 2주차 todo 리스트 (5/7~5/14)

파이썬 기초문풀4
파이썬 기초문풀5
파이썬 중급1
파이썬 중급2
파이썬 중급3
파이썬 중급4
파이썬 중급5~6
파이썬 중급7
파이썬 중급8~9
파이썬 중급문풀1~2
파이썬 중급문풀3
파이썬 중급문풀4

📝 weekly 데이터 사이언스 스쿨 퀴즈
📝 재복습weekly 데이터 사이언스 스쿨 퀴즈

💻 핵심 내용 정리

🏅 문제풀이

실습_01

다음과 같이 출력될수 있도록 이동거리와 이동시간을 반환하는 함수를 만들어보자.

def getDistance(speed, hour, minute):
    ditance = speed * (hour + minute / 60)
    return ditance

#100:75 = 60:x  -->  75*60 /100
def getTime(speed, distence):
    time = distence / speed
    print(f'time: {time}')
    h = int(time)
    m = int((time - h) * 100 * 60 / 100)

    return [h, m]


print('-' * 60)
s = float(input('속도(km/h) 입력: '))
h = float(input('시간(h) 입력: '))
m = float(input('시간(m) 입력: '))
d = getDistance(s, h, m)
print(f'{s}(km/h)속도로 {h}(h)시간 {m}(m)분 동안 이동한 거리: {d}(km)')
print('-' * 60)


print('-' * 60)
s = float(input('속도(km/h) 입력: '))
d = float(input('거리(km) 입력: '))
t = getTime(s, d)
print(f'{s}(km/h)속도로 {d}(km) 이동한 시간: {t[0]}(h)시간{t[1]}(m)분')
print('-' * 60)

실습2

다음과  같이  출력  될  수  있도록  비행기  티켓  영수증  출력  함수를  만들어  보자.

childPrice = 18000
infantPrice = 25000
adultPrice = 50000
specialDC = 50


def formatedNumber(n):
    return format(n, ',')

def printAirPlaneReceipt(c1, c2, i1, i2, a1, a2):

    cp = c1 * childPrice
    cp_dc = int(c2 * childPrice * 0.5)
    print(f'유아{c1}명 요금 : {formatedNumber(cp)}원')
    print(f'유아 할인 대상 {c2}명 요금: {formatedNumber(cp_dc)}원')

    ip = i1 * infantPrice
    ip_dc = int(i2 * infantPrice * 0.5)
    print(f'소아{i1}명 요금 : {formatedNumber(ip)}원')
    print(f'소아 할인 대상 {i1}명 요금: {formatedNumber(ip_dc)}원')

    ap = a1 * adultPrice
    ap_dc = int(a2 * adultPrice * 0.5)
    print(f'성인{a1}명 요금 : {formatedNumber(ap)}원')
    print(f'성인 할인 대상 {a2}명 요금: {formatedNumber(ap_dc)}원')

    print(f'total: {formatedNumber(c1 + c2 + i1 + i2 + a1 + a2)}명')
    print(f'TotalPrice: {formatedNumber(cp + cp_dc + ip + ip_dc + ap + ap_dc)}원')

childCnt = int(input('유아 입력: '))
specialDCChildCnt = int(input('할인 대상 유아 입력: '))

infantCnt = int(input('소아 입력: '))
specialDCInfanCnt = int(input('할인 대상 소아 입력: '))

adultCnt = int(input('성인 입력: '))
specialDCadultCnt = int(input('할인 대상 성인 입력: '))

printAirPlaneReceipt(childCnt, specialDCChildCnt,
                     infantCnt, specialDCInfanCnt, adultCnt,
		specialDCadultCnt )

실습_03

다음과  같이  출력  될  수  있도록  재귀함수를  이용해서  팩토리얼    함수를  만들어보자.

def formatedNumber(n):
    return format(n,',')

def recursionFun(n):

    if n == 1:
        return n

    return n * recursionFun(n-1)

inputNumber = int(input('input number: '))
print(formatedNumber(recursionFun(inputNumber)))

실습_04

다음과  같이  출력  될  수  있도록  단리/월복리  계산기  함수를  만들어보자.

def formatedNumber(n):
    return format(n,',')
    
def singleRatecalculator(m, t, r):

    totalMoney = 0
    totalRateMoney = 0

    for i in range(t):
        totalRateMoney += m * (r * 0.01)

    totalMoney = m + totalRateMoney
    return int(totalMoney)

def multiRateCalculator(m, t, r):
    y = t * 12
    rpm = (r / 12) * 0.01

    totalMoney = m

    for i in range(t):
        totalMoney += totalMoney * rpm

    return int(totalMoney)

money = int(input('예치금(원): '))
term = int(input('기간(년): '))
rate = int(input('연 이율(%): '))

print('[단리 계산기]')
print(f'{term}년 후 총 수령액 : {formatedNumber(singleRatecalculator(money, term, rate))}')

print('[월복리 계산기]')
print(f'{term}년 후 총 수령액 : {formatedNumber(multiRateCalculator(money, term, rate))}')

실습_05

다음과  같이  출력  될  수  있도록  등차  수열의  n번째  값과  합을  출력하는  함수를 
만들어보자.

def sequencecal(n1, d, n):

    valueN = 0; sumN = 0;
    i = 1
    while i <= n:

        if i == 1:
            valueN = n1
            sumN += valueN
            print(f'{i}번째 항의 값: {valueN}')
            print(f'{i}번째 항까지의 합: {sumN}')

            i += 1
            continue

        valueN += d
        sumN += valueN
        print(f'{i}번째 항의 값: {valueN}')
        print(f'{i}번째 항까지의 합: {sumN}')

        i += 1


inputN1 = int(input('a1 입력: '))
inputD = int(input('공차 입력: '))
inputN = int(input('n 입력: '))

sequencecal(inputN1, inputD, inputN)

실습_06

다음과  같이  출력  될  수  있도록  등비  수열의  n번째  값과  합을  출력하는  함수를 
만들어보자

def sequencecal(n1, r, n):

    valueN = 0; sumN = 0;

    i = 1
    while i <= n:

        if i == 1:
            valueN = n1
            sumN += valueN
            print(f'{i}번째 항의 값: {valueN}')
            print(f'{i}번째 항까지의 합: {sumN}')

            i += 1
            continue

        valueN *= r
        sumN += valueN
        print(f'{i}번째 항의 값: {valueN}')
        print(f'{i}번째 항까지의 합: {sumN}')

        i += 1


inputN1 = int(input('a1 입력: '))
inputR = int(input('공비 입력: '))
inputN = int(input('n 입력: '))

sequencecal(inputN1, inputR, inputN)

실습_07

과목별  점수를  입력하면  합격  여부를  출력하는  모듈을  만들어보자. 
(평균  60이상  합격, 과락  40으로  한다.)

# 모듈파일
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 passOrfail as pf
if __name__ == '__main__':
    sub1 = int(input('과목1 점수 입력: '))
    sub2 = int(input('과목2 점수 입력: '))
    sub3 = int(input('과목3 점수 입력: '))
    sub4 = int(input('과목4 점수 입력: '))
    sub5 = int(input('과목5 점수 입력: '))

    pf.exampleResult(sub1, sub2, sub3, sub4, sub5)

실습_08

상품  구매  개수에  따라  할인율이  결정되는  모듈을  만들고, 다음과  같이  계산  결과가 
출력되는  프로그램을  만들어보자.

# 모듈파일
def calculartorTotalPrice(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.calculartorTotalPrice(gs)
            flag = False

    print(f'할인율: {result[0]}%')
    print(f'합계: {dc.formatedNumber(result[1])}원')

실습_09

로또  모듈을  만들고  다음과  같이  로또  결과가  출력될  수  있도록  프로그램을 
만들어보자.


# 모듈파일
import random

userNums = []; randNums = []; collNums = []
randNums = 0

def setUserNums(ns):
    global userNums
    userNums = ns

def getUserNums():
    return randNums
    randNums = random.sample(range(1, 46), 6)

def getRandNum():
    return randNums

def setBonuNum():
    global randBonuNum

    while True:
        randBonuNum = random.randint(1, 45)
        if randBonuNum not in randNums:
            break

def getBonuNum():
    return randBounNum

def lottoResult():
    global userNums
    global randNums
    global collNums

    collNums = []
    for un in userNums:
        collNums.append(un)

    if len(collNums) == 6:
        print('1등 당첨!!')
        print(f'번호: {collNums}')

    elif (len(collNums) == 5) and (randBounNum in userNums):
        print('2등 당첨!!')
    print(f'번호: {collNums}, 보너스 번호: {randNums}')

    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'보너스 번호: {randBonuNums}')
    print(f'선택 번호: {userNums}')
    print(f'일치 번호: {collNums}')


def startLotto():
    n1 = int(input('번호(`1~46 입력: '))
    n2 = int(input('번호(`1~46 입력: '))
    n3 = int(input('번호(`1~46 입력: '))
    n4 = int(input('번호(`1~46 입력: '))
    n5 = int(input('번호(`1~46 입력: '))
    n6 = int(input('번호(`1~46 입력: '))
    selectNums = [n1, n2, n3, n4, n5, n6]

    setUserNums(selectNums)
    setRandNums()
    setBonuNum()

    lottoResult()
    

#실행파일
import lotto as lt

lt.startLotto()

실습_10

순열  계산  모듈을  만들고  다음  순열  계산  결과를  출력해  보자.
#모듈파일
def getPermutaionCnt(n, r):

    result = 1
    for n in range(n, (n-r), -1):
        print('n:{}'.format(n))
        result = result * n

    return result

#실행파일

import permutation as pt

numN = int(input('numN 입력: '))
numR = int(input('numR 입력: '))

print(f'{numN}P{numR}: {pt.getPermutaionCnt(numN,numR)}')


#모듈파일
def getPermutaionCnt(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


#실행파일
import permutation as pt

numN = int(input('numN 입력: '))
numR = int(input('numR 입력: '))

print(f'{numN}P{numR}: {pt.getPermutaionCnt(numN,numR, logPrint = False)}')


실습_11

   조합  계산  모듈을  만들고  다음  조합  계산  결과를  출력해  보자.

#모듈파일
def getCombinationCnt(n, r):

    resultP = 1
    resultR = 1
    resultC = 1

    for n in range(n, (n - r), -1):
        resultP = resultP * n


    for n in range(r, 0, -1):
        resultR = resultR * n

    resultC = int(resultP / resultR)
    
    return resultC
    
#실행파일
import combination as ct

numN = int(input('numN 입력: '))
numR = int(input('numR 입력: '))

print(f'{numN}C{numR}: {ct.getCombinationCnt(numN, numR)}')

💡 오늘을 마무리하면서 ...

몸이 무리데쓰네..
이해는 도무지 안된다. 정상이라는 걸 강조 하니까 열심히 걍 외우는데 맞는가 모르겠다.

😃 Busy Study _ 새벽반 PM 10:00 ~ AM 2:30

여러분 화이팅!! 우리 모두 다 잘 될거예요!

profile
늦깎이 DA/DS 취준생, 이곳은 스터디노트 겸 성장기록장(소통환영이요💜)

0개의 댓글