Hi Varun,

Thanks for your reply.
I agree the problem is logic - but how can one inspect one number using if x%2 == 0 and then compare it to two other numbers which should at the same time be checked for "oddness", just using the basic constructs?

Thanks,
Peter


On 11/22/2012 02:06 PM, Varun Nagpal wrote:
Hi Peter,

The reason why your program is not behaving as it should is not Pythonic but rather logic.

Instead of giving away the code, I would suggest you revisit the 'and' conditions.

The program should print the largest odd number i.e. the number which is largest among all odd numbers.
Instead you are printing the number which is largest AND odd.

--
Varun


On Thu, Nov 22, 2012 at 6:25 PM, Peter O'Doherty <m...@peterodoherty.net <mailto:m...@peterodoherty.net>> wrote:

    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



    _______________________________________________
    Tutor maillist  - Tutor@python.org <mailto:Tutor@python.org>
    To unsubscribe or change subscription options:
    http://mail.python.org/mailman/listinfo/tutor




--
//=============================
-> Peter O'Doherty
-> http://www.peterodoherty.net
-> m...@peterodoherty.net
-> https://joindiaspora.com/people/70716
//=============================

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to