0

I just started learning to programme with Python. I have just tried to use the if elif and else statement but my computation kept telling me there is an indentation error.

I am quite confused as this is a really simple programme. It seems like when I put more than 2 lines of code after the if statement, there will be a problem. Could you please help me with this?

Thank you soooo much

x = raw_input ('Give me a number ')

if x > 100: 
    print 'Big'
    print 'number'
    print 'hahaha'
elif x == 100:
    print 'yeah'
else: 
    print '...' 
  • Could you please provide the whole ErrorMessage? Depending on your editor you have to check that you use identical indentation (not mixing whitespaces and tabs) – MSeifert Feb 09 '16 at 00:41
  • 3
    Are you mixing tabs and spaces? – Steven Rumbalski Feb 09 '16 at 00:41
  • you also want to convert the input to int, or else it will always come back as > 100 (since a string is 'greater than' a number). Try x = int(raw_input('Give me a number ')) – Stidgeon Feb 09 '16 at 00:43

3 Answers3

0

It is very likely, you have tabs in your text.

It is recommended to set up your editor not to use tabs in Python code and possibly convert them to spaces before saving.

Even without such editor configuration, you can fix your code by searching for tabs (you may let it show somehow) and replacing by spaces.

Jan Vlcinsky
  • 42,725
  • 12
  • 101
  • 98
0

You've mixed tabs and spaces. Unlike your text editor, Python 2 treats tabs like Notepad, as enough spaces to reach the next 8-space indentation level. Python 3 treats tabs and spaces as never equivalent.

Turn on "show whitespace" in your editor to see it, and run Python with the -tt flag to make it tell you about mixed tabs and spaces. Your editor may also have a "convert tabs to spaces" tool to fix the problem.

user2357112
  • 260,549
  • 28
  • 431
  • 505
0

A couple of suggestions:

The error sounds like you aren't using whitespace properly make sure every line has consistent spacing (don't mix tabs and whitespace) (like in your question)

also you might wish to modify your code as shown below:

if int(x) > 100: #got to tell python to convert x (a string, str into int)
    print 'Big'
    print 'number'
    print 'hahaha'
elif int(x) == 100:
    print 'yeah'
else: 
    print('...')
Community
  • 1
  • 1
Michal Frystacky
  • 1,418
  • 21
  • 38