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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Python invalid syntax error

  • 10-06-2013 3:45pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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,282 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, Registered Users 2 Posts: 651 ✭✭✭Nika Bolokov


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

    Cheers !


  • Registered Users, Registered Users 2 Posts: 4,101 ✭✭✭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