[파이썬 입문] 제가 만든 함수에 문제가 있어요

22.05.31 16:14 작성 조회수 213

1

아래와 같이 코드를 작성하여 함수를 만들었습니다! 

마지막 4.get_week 함수에서 자꾸 오류가 뜹니다. 이유는 'inst' 가 define 되지 않았다고 하는데, 검색했을 때 자료를 찾지 못하겠네요. 

 

1.get_today_date 함수 제작

def get_today_date():
year = input("현재 년도를 입력해주세요:")
month = input("현재 월를 입력해주세요:")
day = input("현재 일을 입력해주세요:")

return year + '-' + month + '-' + day

get_today_date()

#이렇게 하면 입력하는 칸이 나타남

2. get_difference 함수

from datetime import date

def get_difference(data_string):
now = date(*map(inst,date_string.split('-')))
result = now - date(1950,1,1)
return result.days

3. get_week_by_difference

def get_week_by_difference(days) : #10
week = "일월화수목금토"
return weeks[days % 7]

 

4. get_week

def get_week():
today = get_today_date()
diff = get_difference(today)
today_week = get_week_by_difference(diff)

print(today_week)

get_week()

*오류코드

현재 년도를 입력해주세요:2022
현재 월를 입력해주세요:5
현재 일을 입력해주세요:31
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-64-950ea7f2390c> in <module>()
      6   print(today_week)
      7 
----> 8 get_week()


<ipython-input-64-950ea7f2390c> in get_week()
      1 def get_week():
      2   today = get_today_date()
----> 3   diff = get_difference(today)
      4   today_week = get_week_by_difference(diff)
      5 

<ipython-input-58-d8bf9d33531a> in get_difference(data_string)
      2 
      3 def get_difference(data_string):
----> 4   now = date(*map(inst,date_string.split('-')))
      5   result = now - date(1950,1,1)
      6   return result.days

NameError: name 'inst' is not defined

답변 1

답변을 작성해보세요.

0

서범석님의 프로필

서범석

2022.06.20

1 2 3 4 번이 코드 전문인가요?