IndentationError: unindent does not match any outer indentation level

后端 未结 30 2091
Happy的楠姐
Happy的楠姐 2020-11-21 07:48

When I compile the Python code below, I get

IndentationError: unindent does not match any outer indentation level




        
30条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-21 08:22

    Firstly, just to remind you there is a logical error you better keep result=1 or else your output will be result=0 even after the loop runs.

    Secondly you can write it like this:

    import sys
    
    def Factorial(n): # Return factorial
      result = 0
      for i in range (1,n):
         result = result * i
    
      print "factorial is ",result
      return result
    

    Leaving a line will tell the python shell that the FOR statements have ended. If you have experience using the python shell then you can understand why we have to leave a line.

提交回复
热议问题