Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Python invalid syntax error

Options
  • 10-06-2013 4:45pm
    #1
    Registered Users Posts: 651 ✭✭✭


    Hi All,

    Writing the code below in Python 3.3 I keep getting an invalid syntax error when I try to run it:

    thing ='house'
    animal ='cat'
    if thing == 'animal':
    if animal == 'cat':
    print('This is a cat')
    else:
    print('I dont know what this animal is')
    else:
    print ('I dont know what this thing is')



    Anyone any ideas as to why this is happening? (Bad copy and paste, the text is not indented but hopefully someone can see where I have messed up)

    Much appreciated,

    Nika


Comments

  • Registered Users Posts: 651 ✭✭✭Nika Bolokov


    thing = 'animal'
    animal = 'cat'

    if thing == 'animal':
    if animal == 'cat':
    print ('This is a cat')
    else:
    print ('I dont know what this animal is')

    else:
    print('I dont know what this thing is')


  • Registered Users Posts: 7,157 ✭✭✭srsly78


    The indentation is important in python, leaving it out is not optional.

    Put code tags around your post.


  • Moderators, Computer Games Moderators Posts: 4,281 Mod ✭✭✭✭deconduo


    The code looks fine, but the indentation does matter. This is what it should look like:
    thing ='house'
    animal ='cat'
    if thing == 'animal':
        if animal == 'cat':
            print('This is a cat')
        else:
            print('I dont know what this animal is')
    else:
        print ('I dont know what this thing is')
    


  • Registered Users Posts: 651 ✭✭✭Nika Bolokov


    Thanks so much guys. I had the text indented but the else command was not down properly.

    Cheers !


  • Registered Users Posts: 3,968 ✭✭✭spaceHopper


    What editor are you using, I find pyscripter great as it pick up trouple with indenting and syntax you can also use the interpiter free from to try out cose


  • Advertisement
Advertisement