IndentationError 질문있습니다.

조회수 679회
def isPhoneNumber(text):
    if len(text) != 12:
        return False
    for i in range(0,3):
        if not text[i].isdecimal():
            return False
    if text[3] != '-':
        return False
    for i in range(4,7):
        if not text[i].isdecimal():
            return False
        if not text[i].isdecimal():
    if text[7] != '-':
        return False
    for i in range(8,12):
        if not text[i].isdeciaml():
            return False
    return True

print('415-555-4242 is a phone Number')
print(isPhoneNumber('415-555-4242'))
print('Moshi moshi is a phone number')
print(isPhoneNumber('Moshi moshi'))
if text[7] != '-':
    ^
IndentationError: expected an indented block

틀린곳을 잘모르겠습니다..

  • if not text[i].isdecimal(): 이 부분 아래에 코드가 없어서 그런것 같습니다 ! 최진우 2019.2.16 23:14

2 답변

  • 파이썬인데 인덴트가 안들어가있네요... 적어도 indent정도는 해서 코드를 올려주셔야 답변을 달아주시는분이 읽어주시지 않을까요 ㅠㅠ

    참고로 vscode의 경우 alt + shift + F 를 통해 자동으로 들여쓰기 서식에 맞게 반환을 해줍니다.

    https://stackoverflow.com/questions/29973357/how-do-you-format-code-in-visual-studio-code-vscode

    • (•́ ✖ •̀)
      알 수 없는 사용자
  • def isPhoneNumber(text):
        if len(text) != 12:
            return False
        for i in range(0,3):
            if not text[i].isdecimal():
                return False
        if text[3] != '-':
            return False
        for i in range(4,7):
            if not text[i].isdecimal():
                return False
            if not text[i].isdecimal():
        if text[7] != '-':
            return False
        for i in range(8,12):
            if not text[i].isdeciaml():
                return False
        return True
    
                return False
            if not text[i].isdecimal():
        if text[7] != '-':
            return False
    

    여기서 보면, if text[7] 라인 앞 라인에서 if not 구문이 있어서 그 다음 줄에서 들여쓰기가 되어야 하는데, 들여쓰기가 되어 있지 않습니다.

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)