# 시간 제어 모듈 time
import time
# 현재 시간 정보 확인하기
print(time.localtime())
print(time.localtime().tm_year, time.localtime().tm_mon, time.localtime().tm_mday)
# 2023 5 24
# 일시정지, 자바스크립트의 settimeout과 유사한 기능
print('Stop 1s')
time.sleep(1)
print('Go')
print('Stop 0.5s')
time.sleep(.5)
print('Go')
# [팁] 시간 차이 계산하기
print(time.time()) # 1970년 1월 1일 00:00(UTC) 부터 지난 시간(초)
# 이걸 활용하면
start = time.time()
time.sleep(.3)
end = time.time()
print(end-start)
# 이런식으로 시간이 얼마나 걸렸는지 확인할 수 있다
# 수학 관련 모듈
import math
# 수학 관련 값(변수)
print(math.pi) # 원주율
print(math.e) # 자연수
# 삼각함수
print(math.sin(30)) # 기대한 값 1/2, 0.5
deg_30 = math.pi / 6
print(math.sin(deg_30))
print(round(math.sin(deg_30), 1))
# round(반올림)의 두번째 인자 값으로 들어간 1은 몇번째 소수까지 반올림 할지 결정
deg_30 = math.radians(30)
print(math.sin(deg_30))
print(round(math.sin(deg_30), 1))
# 로그함수
print(math.log(math.e)) # 1.0
print(math.log10(100)) # 2.0
print(math.log2(8)) # 2.0
# 랜덤과 난수 관련 모듈
import random
# 난수 생성
print(random.random()) # 0~1 float
print(random.randint(0, 255)) # 0~255, int
print(random.uniform(0, 255)) # 0~255, float
# 리스트와 랜덤
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
choice = random.choice(numbers) # 비파괴적인 처리
print(choice)
# 샘플 몇개 뽑기
sample = random.sample(numbers, 3) # 리스트 중 랜덤한 3개를 뽑는다
print(sample)
# 섞기
print('=' *20)
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
print(numbers)
random.shuffle(numbers) # 파괴적인 처리
print(numbers)
random.shuffle(numbers) # 파괴적인 처리
print(numbers)
# 파괴적인 처리?
# 자바스크립트의 push()와 concat()의 차이를 생각하면 됩니다.
# 둘다 배열에 데이터를 추가하는 메서드지만
# 실행한 순간 원본 배열을 변경해버리는 .push()와
# 실행하여도 원본 배열은 변경하지 않는 concat()의 차이
sys - 시스템 관련 모듈
# 시스템 관련 모듈
import sys
# 터미널에서 입력한 인자 값 사용하기
# 실행 시 명령어 python(리눅스나 맥은python3) 08_sys.py spencer 7 202.2
# Day03 터미널로 이동해서(파이썬이 아니라 터미널)
# python 08_sys.py spencer 7 202.2 입력
# ['08_sys.py', 'spencer', '7', '2022'] 출력을 확인
print(sys.argv[0]) # 파일 경로만 나옴
print(sys.argv[1])
print(sys.argv[2])
print(sys.argv[3])
# 이렇게하면 1,2,3에 spencer, 7,2002가 할당이 되야 하는데 뭐가 문제인지 할당이 안되는 상황
# 일단 진도를 위해 넘어감