Python “expected an indented block”

前端 未结 9 1169
广开言路
广开言路 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:43

    in python .....intendation matters, e.g.:

    if a==1:
        print("hey")
    
    if a==2:
       print("bye")
    
    print("all the best")
    

    In this case "all the best" will be printed if either of the two conditions executes, but if it would have been like this

    if a==2:
       print("bye")
       print("all the best")
    

    then "all the best" will be printed only if a==2

    0 讨论(0)
  • 2020-12-09 08:44

    This one is wrong at least:

                for x in range(x, 1, 1):
            elif option == 0:
    
    0 讨论(0)
  • 2020-12-09 08:49

    Your for loop has no loop body:

    elif option == 2:
        print "please enter a number"
        for x in range(x, 1, 1):
    elif option == 0:
    

    Actually, the whole if option == 1: block has indentation problems. elif option == 2: should be at the same level as the if statement.

    0 讨论(0)
提交回复
热议问题