[45~50] 근삿값 ~ 평균 문풀

이재은·2024년 5월 28일

45강.

class NearAlgorithm :

    def __init__(self, d):
        self.temps = {0:24, 5: 22, 10: 20, 15:16, 20: 13, 25: 10, 30: 6}
        self.depth = d
        self.nearNum = 0
        self.minNum = 24 #임의의 값으로 초기화

    def getNearNumbers(self): #근사치를 가져오는 것

#이걸 빨리 깨우쳐야 하는디.. 임의값보다 작으면 다시 초기화해주고

        for n in self.temps.keys(): #0, 5, 10, 15
            absNum = abs(n - self.depth)
            if absNum < self.minNum :
                self.minNum = absNum
                self.nearNum = n
               
import nearMod

depth = int(float(input('input depth : '))) #정수실수모두이용(12.5) 이런거 입력
print(f'depth : {depth}')

na = nearMod.NearAlgorithm(depth)
temp = na.getNearNumbers()
print(f'{temp}도')

46강.

#안히.. 왜 자꾸 오류나
    def printuserCondition(self):

        for n in self.BMISection.keys():
            absNum = abs(n-self.userBMI)
            if absNum < self.minNum :
                self.minNum = absNum
                self.nearNum = n

        print(f'self.nearNum : {self.nearNum}')
        ##이부분..!!!
        if self.userBMI <= self.nearNum :
            self.condition = self.BMISection[self.nearNum][0]
        else :
            self.condition = self.BMISection[self.nearNum][1]
            
        print(f'{self.condition}')

47강.

def salesUpAndDown(ss) :
	#재귀함수도 끝나는 경우가 있어야함
    if len(ss) == 1 :
        return ss

    print(f'sales : {ss}')
    currentSales = ss.pop(0)
    nextSales = ss[0]
    increase = nextSales  - currentSales
    if increase > 0 :
        increase = '+' + str(increase)
    print(f'매출 증감액 : {increase}')

    return salesUpAndDown(ss) #재귀함수

48강.

#입력한 값들 사이의 값을 더하기 
#변수초기화, 계속 더하기, 그리고 빼기 
class NumsSum :

    def __init__(self, n1, n2):
        self.bigNum = 0
        self.smallNum = 0
        self.setN1N2(n1, n2) #자동으로 초기화..?


    def setN1N2(self, n1, n2):
        self.bigNum = n1
        self.smallNum = n2

        if n1 < n2 :
            self.bigNum = n2
            self.smallNum = n1

            #재귀함수 : 10까지 더한거 구하하고, 3까지 구한거 빼고

    def addNum(self, n):
        if n <= 1:
            return n
        return n + self.addNum(n-1)

    def sumBetweenNums(self):
        return self.addNum(self.bigNum - 1) - self.addNum(self.smallNum)

49강

#여긴 뭔뎅..?ㅠㅠ
        if self.newScore >= self.currentScores[nearIdx] :
            for i in range(len(self.currentScores)-1 , nearIdx, -1):
                self.currentScores[i] = self.currentScores[i-1]
                
        else  :
            for i in range(len(self.currentScores)-1 , nearIdx+1, -1):
                self.currentScores[i] = self.currentScores[i-1]
            self.currentScores[nearIdx + 1] = self.newScore

50강.

print('+' + str(round(kor_gap, 2)) if kor_gap > 0 else (round(kor_gap, 2)))
print('+' + str(round(eng_gap, 2)) if eng_gap > 0 else (round(eng_gap, 2)))
profile
Dare to be an optimist

0개의 댓글