Python “expected an indented block”

前端 未结 9 1191
广开言路
广开言路 2020-12-09 08:00

Let me start off by saying that I am COMPLETELY new to programming. I have just recently picked up Python and it has consistently kicked me in the head with one recurring e

9条回答
  •  青春惊慌失措
    2020-12-09 08:41

    There are several issues:

    1. elif option == 2: and the subsequent elif-else should be aligned with the second if option == 1, not with the for.

    2. The for x in range(x, 1, 1): is missing a body.

    3. Since "option 1 (count)" requires a second input, you need to call input() for the second time. However, for sanity's sake I urge you to store the result in a second variable rather than repurposing option.

    4. The comparison in the first line of your code is probably meant to be an assignment.

    You'll discover more issues once you're able to run your code (you'll need a couple more input() calls, one of the range() calls will need attention etc).

    Lastly, please don't use the same variable as the loop variable and as part of the initial/terminal condition, as in:

                for x in range(1, x, 1):
                    print x
    

    It may work, but it is very confusing to read. Give the loop variable a different name:

                for i in range(1, x, 1):
                    print i
    

提交回复
热议问题