DAY 6 [모듈]

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("비겼습니다.")

 

'일지' 카테고리의 다른 글

Day 8 [순서도: 선택구조]  (1) 2025.02.28
Day 7 [함수만들기]  (0) 2025.02.27
DAY 6 [집합 자료형][불 자료형][자료구조]  (0) 2025.02.25
DAY 6 [딕셔너리]  (0) 2025.02.25
DAY 6 [리스트]  (0) 2025.02.25
'일지' 카테고리의 다른 글
  • Day 8 [순서도: 선택구조]
  • Day 7 [함수만들기]
  • DAY 6 [집합 자료형][불 자료형][자료구조]
  • DAY 6 [딕셔너리]
joo_coding
joo_coding
2025.02.18~
  • joo_coding
    주코딩일지
    joo_coding
  • 전체
    오늘
    어제
    • 분류 전체보기 (134) N
      • 일지 (19)
      • 계획표 (7)
      • C언어 (35)
        • 연습장 (12)
      • 과제 (2)
      • C++ (3)
      • python (28)
        • 연습장 (11)
      • TCP IP (4)
      • DB (2)
      • ubuntu (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    c언어 #vscode #gcc #윈도우 #c언어윈도우 #gcc윈도우 #vscode윈도우 #c #c++
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
joo_coding
DAY 6 [모듈]
상단으로

티스토리툴바