-1

I used this method

for n in range(10,99):

  def firstDigit(n) :
 
     while n >= 10:
         n = n / 10;
     

     return int(n)
 

  def lastDigit(n) :
 
    
     return (n % 10)
     
 z = firstDigit(n)**2 + lastDigit(n)**2 + firstDigit(n) + lastDigit(n);

 if z == n:

  print(z)

But gave this error why?

IndentationError: unindent does not match any outer indentation level

Michael Butscher
  • 10,028
  • 4
  • 24
  • 25
Paku
  • 1

2 Answers2

0

Paku.

By the error, i can only infer that there is a problem at the indentation. Are you sure your function looks exacly like this?

for n in range(10,99):

    def firstDigit(n):
 
         while n >= 10:
             n = n / 10;
    
         return int(n)

def lastDigit(n):
    return (n % 10)
     
z = firstDigit(n)**2 + lastDigit(n)**2 + firstDigit(n) + lastDigit(n);

if z == n:
    print(z)

bellotto
  • 445
  • 3
  • 13
0

You have to indent every time you use a loop , function or decision statement: for, while,def or if. Python is VERY sensitive about indenting. Here, you have to indent your variable z with the same vertical line of def. So, your code needs to be like this

for n in range(10,99):

  def firstDigit(n) :
 
     while n >= 10:
         n = n / 10;
     

     return int(n)
 

  def lastDigit(n) :
 
    
     return (n % 10)
     
  z = firstDigit(n)**2 + lastDigit(n)**2 + firstDigit(n) + lastDigit(n);

  if z == n:

     print(z)
Python learner
  • 1,159
  • 1
  • 8
  • 20