일지
DAY 6 [모듈]
joo_coding
2025. 2. 25. 19:07
# p.200
# 현재 시각 찍기 (연월일시)
# 모듈 - 라이브러리
# 사람들이 자주 사용하는 기능은 누군가 만들어놨다.
# = 파이썬 내장함수
# ex) print, input
# 표준 라이브러리 = 파이썬이 기본 제공해주는 기능
# 라이브러리 = 누가 이미 만들어놓은 기능
# 파이썬에서는 모듈이라고 부른다.
print(datetime.datetime.now())
print(datetime.datetime.now().hour) # 시간만 출력하기
now = datetime.datetime.now()
print(now.minute)
print(now.day)
print(now.year)
# 자주 쓰는 라이브러리들
# os sys glob math itertools time(datetime) random shutil jason thread urllib pickle
# os / sys / shutil
# 컴퓨터 조작에 관한 기능
# glob : 파일 찾을 때
# math : 수학 할 때
# itertools : 반복, 조합, 콤비네이션
# jason : 자료구조를 읽거나 만들 때
# pickle : 파이썬 형태로 저장할 때
# 스레드랑 urllib 은 어려워서 못씀
[os]
# os는 맨위에 있는게 좋다.
# os
import os
print(os.path.exists("./main5_3_1.py"))
#--위치
# os야 경로인데 존재하는지 확인해줘
print(os.path.exists("./abc.py")) #안갖고있는 파일은 False
# 파일경로
# 1.절대경로 2.상대경로
cmd
[random]
# 1% 확률을 구현하라!
# 몇번만에 1이 나왔는지
import random
count = 1
while True:
rate = random.randint(1, 100)
if rate <= 1:
print(count)
break
count += 1
# 로또1
import random
list = []
for i in range(1, 46):
list.append(i)
random.shuffle(list)
print(sorted(list[:6]))
# 로또2
import random
list = []
for i in range(1, 46):
list.append(i)
lotto = random.sample(list, 6)
print(sorted(lotto))
# 1개만 뽑고싶다.
import random
list = []
for i in range(1, 46):
list.append(i)
choice_ = random.choice(list)
print(choice_)
[가위바위보]
#컴퓨터랑 가위바위보
#나는 입력하는거고
#컴퓨터는 랜덤하게 나오는거고
rsp = ["가위", "바위", "보"]
result = ["이겼다.", "졌다.", "비겼다."]
while True:
player = input("무엇을 내시겠습니까?: ")
computer = random.choice(rsp)
print(computer)
# if player == computer:
# print("비김")
if player == rsp[0]: #가위
if computer == player:
print("비겼습니다.")
elif computer == rsp[1]:
print("컴퓨터가 이겼습니다.")
elif computer == rsp[2]:
print("컴퓨터가 졌습니다.")
if player == rsp[1]: #바위
if computer == rsp[0]:
print("컴퓨터가 졌습니다.")
elif computer == rsp[1]:
print("컴퓨터가 이겼습니다.")
elif computer == rsp[2]:
print("플레이어가 이겼습니다.")
if player == rsp[2]: #보
if computer == rsp[0]:
print("컴퓨터가 이겼습니다.")
elif computer == rsp[1]:
print("컴퓨터가 졌습니다.")
elif computer == rsp[2]:
print("비겼습니다.")