3 Replies - 354 Views - Last Post: 20 June 2013 - 05:03 AM Rate Topic: -----

#1 thebrain22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-June 13

Having trouble with simple Python program

Posted 19 June 2013 - 04:23 PM

I'm creating an English to Pig Latin translator on Codeacademy and everytime i compile this code it says this on line 8---Indentationerror: unindent does not match any outer indentation level and is ..
Does anybody know how to fix this problem
pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
   if first == 'a'or 'e' or 'i' or 'o' or 'u':
         print "vowel"
    else:
         print 'empty'
else:
    print "consanent"
original.lower()
word = original.lower()
first = original[0]

This post has been edited by jon.kiparsky: 25 June 2013 - 07:04 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Having trouble with simple Python program

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2113
  • View blog
  • Posts: 3,235
  • Joined: 21-June 11

Re: Having trouble with simple Python program

Posted 19 June 2013 - 04:35 PM

As the error message is telling you, your indentation on line 8 is not the same as on any other line. The indentation of else should be the same as that of the if that it belongs to. In this case the relevant if has four spaces of indentation, so your else should also have four spaces of indentation - but it has five.
Was This Post Helpful? 1
  • +
  • -

#3 chan 06  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 63
  • Joined: 07-October 12

Re: Having trouble with simple Python program

Posted 19 June 2013 - 11:27 PM

You should look at lines 8-10 because you cannot have 2 else statements. Find the length of your original variable, and if the original variable has length of 0 than print that it is empty. If you need further help post on forums and other people can help you.
Was This Post Helpful? 0
  • +
  • -

#4 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2113
  • View blog
  • Posts: 3,235
  • Joined: 21-June 11

Re: Having trouble with simple Python program

Posted 20 June 2013 - 05:03 AM

Another problem I just noticed:

if first == 'a'or 'e' or 'i' or 'o' or 'u':


This won't work as you want it to. or treats all of its operands as conditions so if first == 'a' or 'e' means "if the condition first == 'a' is true or if the condition 'e' is true". 'e' is a rather funny condition since it's a plain value and not even a boolean value. How Python handles this is it treats any non-boolean values that aren't 0 or empty as true. So since 'e' is a non-empty string it's handled as true and the condition becomes "if first == 'a' is true or if true is true". Since "true is true" is an obvious tautology, the condition is also true.

What you want is something like:
if first == 'a' or first == 'e' or ...':


But since that will be getting kind of long, you can shorten it by using a list:

if first in ['a', 'e', 'i', 'o', 'u']:


Or put the list into a variable:
vowels = ['a', 'e', 'i', 'o', 'u']
if first in vowels:



View Postchan 06, on 20 June 2013 - 08:27 AM, said:

You should look at lines 8-10 because you cannot have 2 else statements.


He has two ifs, so of course he can have two elses. You can have one else per if.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1