-
Math modulePython/etc. 2020. 7. 28. 14:36반응형
| import vs from~ import
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersimport greet greet.hello('정수정') greet.niceMeet('이승연') from greet import hello, niceMeet hello('정수연') niceMeet('김제니') This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersdef hello(name): print('%s님 안녕하세용~~'%name) def niceMeet(name): print('%s님 만나서 반갑습니당다라당~'%name) 사용법 : import greet from greet import hello, niceMeet
함수 : greet.hello() hello()
greet.niceMeet() niceMeet()
| Math Module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersimport math print('3.6의 소수점 절삭 : %.1f'%math.floor(3.6)) print('5.1의 무조건 올림 :%.1f'%math.ceil(5.1)) print('6.3의 반올림 : %.1f'%round(6.3)) print('6.6의 반올림 : %.1f'%round(6.6)) #팩토리알 구하기 print('5의 팩토리알(1*2*3*4*5):%d'%math.factorial(5)) #삼각함수 print('sin(pi/4): %.2f'%math.sin(math.pi/4)) print('cos(pi): %.2f'%math.cos(math.pi)) print('tan(pi/6): %.2f'%math.tan(math.pi/6)) #거듭제곱, 제곱근, 로그 구하기 print('5의 3승 : %d'%math.pow(5,3)) print('144의 제곱근 : %d'%math.sqrt(144)) print('log10(1000):%.2f'%math.log10(1000)) 2행 : math.floor(3.47) -> 3 : 내림
3행 : math.ceil(5.1) -> 6 : 올림
4,5행 : math.round(A) : 반올림 값을 반환
7행 : math.factorial(5) -> 120 : 팩토리알 값 반환
math.fabs(-3) -> 3 ->절대값
matth.log(10,10) ->1 : math.log(a,b) b를 밑으로 하는 log a에 대한 로그 값 반환
math.log10() :10을 밑으로 하는 log 함수
math.pow(3,2) ->9 : math.pow(x,y)는 x에 y승을 계산한 결과를 반환
math.sqrt(25) -> 5.0 : 제곱근의 값을 반환
math.cos(x) :코사인
math.sin(x) : 사인
***상수***
math.pi :원주율 값을 반환
math.e : 자연 상수 값 반환
math.tau : 타우 값을 변환
참고 :
위키독스
온라인 책을 제작 공유하는 플랫폼 서비스
wikidocs.net
728x90'Python > etc.' 카테고리의 다른 글
Github Desktop push가 안되는 문제! 에러! (0) 2024.11.04 문자열(String) (0) 2020.07.28 기본 문법(연산자) (0) 2020.07.28