0

Here’s a problem that I was trying to solve:

Ask the user for a string and print out whether this string is a palindrome or not. (A palindrome is a string that reads the same forwards and backwards.)

The code that I wrote was

print('Please type in one word which you want to check!')
num=input()

if (int(len(num))%2)==0:
    for i in range(int(len(num)/2)):
        if num[i]==num[-(i+1)]:
            if num[int((len(num)/2)-1)]==num[-(i+1)]:
                print('Yes the word is palidrome.')
                break
            else:
                pass
        else:
            print('No. The word is not palindrome.')
            break

elif (int(len(num))%2)!=0:
    for i in range(int((len(num)-1)/2)):
        if num[i]==num[-(i+1)]:
            if num[int(((len(num)-1)/2)-1)]==num[-(i+1)]:
                print('Yes the word is palidrome.')
                break
            else:
                pass
        else:
            print('No. The word is not palindrome.')
            break

The code is working perfectly fine.

The problem is that I have to relaunch the Shell every time I want to see whether a word is palindrome or not. So I thought that it would be cool to use a while loop.

I changed the code as follows ( by simply writing while True and leaving some spaces as shown below ) :

while True:
  print('Please type in one word which you want to check!')
  num=input()

  if (int(len(num))%2)==0:
    for i in range(int(len(num)/2)):
        if num[i]==num[-(i+1)]:
            if num[int((len(num)/2)-1)]==num[-(i+1)]:
                print('Yes the word is palidrome.')
                break
            else:
                pass
        else:
            print('No. The word is not palindrome.')
            break

  elif (int(len(num))%2)!=0:
    for i in range(int((len(num)-1)/2)):
        if num[i]==num[-(i+1)]:
            if num[int(((len(num)-1)/2)-1)]==num[-(i+1)]:
                print('Yes the word is palidrome.')
                break
            else:
                pass
        else:
            print('No. The word is not palindrome.')
            break

Python shows:

Inconsistent use of tabs and spaces in indentation

Why am I getting this and how do I fix it?

Aaryan Dewan
  • 204
  • 3
  • 11

1 Answers1

1

Inconsistent use of tabs and spaces in indentation

It means exactly what it says. You have mixed tabs and spaces in your source file. You can only use one or the other in each individual Python script.

Try looking here for a solution: How to fix python indentation

Remolten
  • 2,614
  • 2
  • 25
  • 29
  • Yeah! I had to add a tab to every line in the code and then it worked! Is there some easier way to do that ? – Aaryan Dewan Jun 23 '17 at 14:35
  • @AaryanDewan In sublime text, there is. At the bottom bar, there is a button which says `Tab size: xxx` or `Spaces: xxx`. Do Ctrl+A. Click the button, then click on `Indent using xxx`. – cs95 Jun 23 '17 at 14:44