Print the largest odd number Ask user to input 10 integers and then print the largest odd number that was entered. If no odd number was entered, print a message to that effect.

I've written this code as my solution to the above exercise from chapter 2 of Computation and Programming Using Python by John Guttag. The book is meant to be used with Python 2.x. I need to know if the code can be "straightened up" in any way. So far, the book has covered variable assignment, print function, conditional branching, and loops.

largestOddNumber = None

for _ in range(10):  # '_' is a throw-away var
    number = int(raw_input('Enter an integer: '))
    if number % 2 != 0 and number &gt; largestOddNumber:
        largestOddNumber = number

print largestOddNumber or 'No odd number was entered.'
Code looks good! I only have minor/pedantic comments:

for _ in range(10):  # '_' is a throw-away var


That comment is useless, the naming of the variable as _ is sufficient to indicate that we don't intend on using it. Also, in python2.7, range() returns a full list of all the values, which can get pretty inefficient as you go up, so you should prefer to use its lazier cousin, xrange():

for _ in xrange(10):


Then this:

print largestOddNumber or 'No odd number was entered.'


While I do like that or in python, rather than returning a bool returns the first argument that isn't False/None, it's a little difficult to read. Now, the code is perfectly correct for odd numbers but would actually be wrong for even numbers - if 0 ended up being the largest even number, we'd print the string. So I find it simpler to just be explicit:

if largestOddNumber is not None:
    print largestOddNumber
else:
    print 'No odd number was entered'


But really, the code is fine.