빅데이터 & 딥러닝 스터디/파이썬 스터디(김변수와 시작하는 코딩생활 3기)
8/17 (수) 김변수와 시작하는 코딩생활 with 파이썬 스터디 11일차(선택4 2022년 a월 b일은 무슨요일)
승이네
2022. 8. 17. 00:14
반응형
선택 과제 : 3-16. 2022년 a월 b일은 무슨 요일
날짜를 입력받고, 2022년을 기준으로 입력받은 날짜가 무슨 요일인지 구하는 프로그램을 작성해 보세요.
조건1 : 2022년 1월 1일은 토요일입니다.
조건2 : 2022년은 윤년이 아닙니다.(2월이 28일이다.)
month = int(input("월 : "))
day = int(input("일 : "))
n = 0
total_day = 0
day_list = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
what_day = ["월", "화", "수", "목", "금", "토", "일"]
for i in range(0, month):
if month == 0 or month == 2 or month == 4 or month == 6 or month == 7 or month == 9 or month == 11 or month == 12:
total_day = total_day + day_list[i]
if month == 1:
total_day = total_day + day_list[i]
if month == 3 or month == 5 or month == 8 or month == 10:
total_day = total_day + day_list[i]
total_day = total_day - day_list[i]
total_day = total_day + day
if total_day % 7 == 1:
n = 5
if total_day % 7 == 2:
n = 6
if total_day % 7 == 3:
n = 0
if total_day % 7 == 4:
n = 1
if total_day % 7 == 5:
n = 2
if total_day % 7 == 6:
n = 3
if total_day % 7 == 0:
n = 4
if month > 12 or day > day_list[i]:
print("잘못된 입력입니다. 월과 일을 확인하세요.")
else:
print(f"{month}월 {day}일은 {what_day[n]}요일 입니다.")
월을 13으로 했을 때 다음과 같은 에러가 뜨는데 어떻게 고쳐야 할지 모르겠습니다.
코드가 제 기준에서 복잡해서 하나씩 건드니까 고장이 나네요 ㅠㅠ
반응형