0 votes
1 view
in Python by (29.4k points)

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 error -- "expected an indented block" Now, I know there are several other threads addressing this problem and I have looked over a good number of them, however, even checking my indentation has not given me better results. I have replaced all of my indents with 4 spaces and even rewritten the code several times. I'll post this counter assignment I got as an example.

option == 1 

while option != 0: 

   print "MENU" 

   option = input() 

   print "please make a selection" print "1. count" 

  print "0. quit" 

  if option == 1:

     while option != 0:

       print "1. count up" 

       print "2. count down" 

       print "0. go back" 

       if option == 1: 

          print "please enter a number" 

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

             print x 

          elif option == 2: 

              print "please enter a number" 

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

          elif option == 0: 

              break 

          else: 

             print "invalid command" 

elif option == 0:

break

1 Answer

0 votes
by (70.7k points)
edited by

Like other programming languages Python does not use curly braces instead it used indentation block see the example below:-

if a==1:

   print("hey") 

if a==2:

   print("bye")

   print("Happy coding")

The above code will print  "all the best" if either of the two conditions executes, but if it would have been like this

if a==2: 

  print("bye")

  print("Happy coding")

Then “all the best" will be printed only if a==2.

To know more about this you can have a look at the following video tutorial:-

...