IndentationError: unindent не соответствует ни одному внешнему уровню отступа в Python 3, выясните причину, по которой - PullRequest
0 голосов
/ 10 июля 2019
number = 64
running = True

while running:
        guess = int(input("write the number :"))
    if guess == number:
            print("Congrads! You won!")
            running = False
    elif guess < number:
        print("No, the number is a bit bigger")
    else:
        print("No, the number is less")
else:
    print("while cycle is over.")
else:
    print("end")

я ожидал работающий код, но есть ошибки, которые я не вижу, в четвертой строке говорится о проблеме, но опять же, я не вижу в этом ничего плохого

1 Ответ

0 голосов
/ 10 июля 2019

Помимо Дж. Андерсона в коде есть следующие ошибки (см. Комментарии):

number = 64
running = True

while running:
        guess = int(input("write the number :")) # <-- is indented too much
    if guess == number:
            print("Congrads! You won!") # <-- also indented "two tabs"
            running = False # <-- also indented "two tabs"
    elif guess < number:
        print("No, the number is a bit bigger")
    else:
        print("No, the number is less")
else:
    print("while cycle is over.")
else: # <-- second else?
    print("end")

Это было бы исправлением:

number = 64
running = True

while running:
    guess = int(input("write the number :"))
    if guess == number:
        print("Congrads! You won!")
        running = False
    elif guess < number:
        print("No, the number is a bit bigger")
    else:
        print("No, the number is less")
else:
    print("while cycle is over.")
...