April 13th, 2013, 05:20 AM

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!'
April 13th, 2013, 09:17 AM

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!
April 13th, 2013, 10:01 AM

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!
April 13th, 2013, 10:16 AM

Skip ahead to the next exercise.
[code]
Code tags[/code] are essential for python code and Makefiles!