[Tutor] Beginner's question

Peter O'Doherty mail at peterodoherty.net
Thu Nov 22 13:55:01 CET 2012


Hi list,
Firstly, apologies for the low-level nature of this question - it's 
really quite basic but I don't seem to be able to solve it.

I need to write a program that examines 3 variables x, y, z, and prints 
the largest odd number. I've tried all sorts of variations and this is 
the current version:

x, y, z = 26, 15, 20

if x > y and x > z and x%2 != 0:
     print 'x is largest and odd'
elif y > x and y > z and y%2 != 0:
     print 'y is largest and odd'
elif z > x and z > y and z%2 != 0:
     print 'z is largest and odd'
else:
     print 'no odd'


A solution should be possible using only the simple operators and 
keywords above, no functions, lists or any other form of iteration. 
(It's from p. 16 of Introduction to Computation and Programming Using 
Python, and no, it's not "homework"!)

Many thanks,
Peter





More information about the Tutor mailing list