도와주세요! IndentationError: unindent does not match any outer indentation level
조회수 38236회
발생하는 문제 및 실행환경
이 코드를 실행하면 에러가 뜹니다 ㅜㅜ 왤까요?
소스코드
import sys
def Factorial(n): # Return factorial
result = 0
for i in range (1,n):
result = result * i
print "factorial is ",result
return result
에러내용
IndentationError: unindent does not match any outer indentation level
1 답변
-
다른 문제는 없는 것 같고 아마 들여쓰기에서 tab과 space를 같이 써서 에러가 발생한 듯합니다.
그리고 result = 0이 아니라 1로 설정해야 Factorial 값이 제대로 나올 것 같네요.
import sys def Factorial(n): # return factorial result = 1 for i in range (1,n): result = result * i print "factorial is ",result return result print Factorial(10)
PEP8과 관련된 글 파이썬에서 들여쓰기는 탭 & 스페이스 중 어느 걸로 하시나요?을 봐주세요
댓글 입력