#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    Easy beginners' problem has me stumped


    Hi Everyone. Sorry if this is first day stupidity (never written code before in my life), but I wrote this program to take three previously assigned int variable x, y and z and return the largest odd number (or say that there isn't one). But it keeps complaining about a syntax error where the last if statement is (the one that goes if z%!=0. I think it is something wrong with the indentation but can't fix it for the life of me. Thank you for your help sorting this out.
    if x>y:
    x,y=y,x
    if y>z:
    y,z=z,y
    if x>y:
    x,y=y,x
    print x,y,z
    else:
    print x,y,z
    else:
    print x,y,z
    elif y>z:
    y,z=z,y
    if x>y:
    x,y=y,x
    print x,y,z
    else:
    print x,y,z
    else:
    print x,y,z

    if z%2!=0:
    print 'The largest odd number is: ',z
    elif y%2!=0:
    print 'The largest odd number is: ',y
    elif x%2!=0:
    print 'The largest odd number is: ',x
    else:
    print 'There are no odd numbers present!'
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,895
    Rep Power
    481
    No problem found.
    Code:
    (x,y,z,) = (int(100*random.random())for i in 'abc')
    
    print('input: {}'.format((x,y,z)))
    
    if x>y:
        x,y=y,x
        if y>z:
            y,z=z,y
            if x>y:
                x,y=y,x
                print x,y,z
            else:
                print x,y,z
        else:
            print x,y,z
    elif y>z:
        y,z=z,y
        if x>y:
            x,y=y,x
            print x,y,z
        else:
            print x,y,z
    else:
        print x,y,z
    
    if z%2!=0:
        print 'The largest odd number is: ',z
    elif y%2!=0:
        print 'The largest odd number is: ',y
    elif x%2!=0:
        print 'The largest odd number is: ',x
    else:
        print 'There are no odd numbers present!'
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    thank you


    Thank you b49P23TIvg! You confirmed my suspicions that nothing was wrong with the code. But I couldn't rule out the newbie doubt tat it is just me missing the obvious. So I restarted my computer, and retried. Same result. I uninstalled and reinstalled the python 2.7 shell (the one my book requires) and tried all over again. Same result. Very frustrating!
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,895
    Rep Power
    481
    Skip ahead to the next exercise.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo