인문대생의 데이터 직군 취업로그 12

류지윤·2023년 6월 16일
0
post-thumbnail

[ 오늘의 수업내용 요약 ]

[ 연습문제 1 ]
040- 045_ 함수

  • 서로 다른 단위를 연산할 때 시간/분 환산 주의하기
  • recursion 재귀함수 호출 함수
  • 숫자 끊어읽기 함수
    : def formatedNumber(n):
    return format(n, ‘,’)
  • 등차수열 공식 : a1 + (n2) *d
  • 등차수열 합 공식: sn = n *(a1 + an) / 2
_def mul(n1, n2):
    return n1 * n2
def div(n1, n2):
    return n1 / n2
def mod(n1, n2):
    return n1 % n2
def flo(n1, n2):
    return n1 // n2
def exp(n1, n2):
    return n1 ** n2

while True:
    print('-' * 60)


    selectNum = int(input('1. 덧셈 2. 뺄셈 3. 덧셈 4. 나눗셈 5. 나머지 6. 몫 7. 제곱승 8. 종료'))
    if selectNum == 8:
        print('bye')
        break

    num1 = float(input('첫번째 숫자 입력 : '))
    num2 = float(input('두번째 숫자 입력 : '))
    if selectNum == 1:
        print(f'{num1} + {num2}: {add(num1, num2)}')

    elif selectNum == 2:
        print(f'{num1} - {num2}: {sub(num1, num2)}')
    elif selectNum == 3:
        print(f'{num1} * {num2}: {mul(num1, num2)}')
    elif selectNum == 4:
        print(f'{num1} / {num2}: {div(num1, num2)}')
    elif selectNum == 5:
        print(f'{num1} % {num2}: {mod(num1, num2)}')
    elif selectNum == 6:
        print(f'{num1} // {num2}: {flo(num1, num2)}')
    elif selectNum == 7:
        print(f'{num1} ** {num2}: {exp(num1, num2)}')
    else:
        print('잘못입력했습니다.')
    print('-' * 60)

0개의 댓글