inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

397

HY J

작성한 질문수 1

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

파이썬 python 파이썬기초 파이썬함수

답변 1

0

서범석

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

슬롯 관련 문의

1

9

2

수업노트가 어디에 있나요?

0

18

1

[긴급요청] 28강 동영상 전체에 오디오가 잘못들어가있습니다.

0

15

1

실제 계좌 잔고 및 테스트중에

1

28

4

Replit UI 변경으로 인한 실습 진행 문의

1

14

1

29강 5:00

0

20

2

설치 및 설정 가이드 노션 자료는 없나요 ?

0

21

2

실기시험 제출관련

0

151

2

6.20 작업형 2 과적합

0

157

3

install까지 설치 하였는데 start 가안됩니다.

1

26

1

8분54초 테이블 내용 문의

0

22

1

코딩팡 장업형2 베이스 라인 인코딩 종류 질문

0

48

2

multi_tool_agent.py 에서 arxiv tool 에러

0

18

1

로지스틱회귀, 회귀

0

48

2

가상 환경과 차이 도커 질문

0

24

1

자료 다운로드 위치 확인 부탁드립니다.

0

15

1

회귀 문제를 풀때 질문입니다.

0

55

1

불균형 처리 후 성능이 더 낮아졌다면,

0

61

2

실기 체험 제2유형 에러 문의

0

61

1

LIGHTGBM 으로 하면 pred값이 소수점 6자리까지 나오는게 맞나요

0

50

2

안녕하세요

1

38

3

3번문제 등분산 가정

0

47

2

작업형3 target 형 변환 질문

0

35

2

[작업형1] 연습문제 섹션1 ~ 10 의 section4

0

36

3