Find 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.

The above exercise is from chapter 2 of Computation and Programming Using Python by John Guttag. So far, the book has covered variable assignment, print function, conditional branching, and loops. The book is about problem solving and uses Python only as a tool to solve problems and it is meant to be used with Python 2.x. I need to know if my solution to the exercise can be "straightened up" in any way.

numbers_entered = []

for _ in range(10):
    number = raw_input('Enter an integer: ')
    if number.isdigit():
        number = int(number)
        numbers_entered.append(number)
    else:
        print 'That was not an integer!'

odd_numbers = []

for item in numbers_entered:
    if item % 2 != 0:
        odd_numbers.append(item)

if odd_numbers:
    print 'The largest odd number entered was %s.' % str(max(
            odd_numbers))
else:
    print 'No odd number was entered.'
Bug

At the end of the first loop,
how many numbers will be in numbers_entered?
10? Hopefully.
In reality: 10 minus invalid entries,
and I'm not sure that was your intention.

This way the invalid entries will be skipped, and there will always be 10 entries in list:

while True:
    number = raw_input('Enter an integer: ')
    if number.isdigit():
        number = int(number)
        numbers_entered.append(number)
        break
    else:
        print 'That was not an integer!'


Handling invalid input

The user input should be valid,
invalid inputs should be the exception.
So you can simplify the handling of invalid user inputs using exceptions:

try:
    number = int(raw_input('Enter an integer: '))
    numbers_entered.append(number)
except ValueError:
    print 'That was not an integer!'


See also the glossary, and search for the word "forgiveness" in it.

Using list comprehensions

List comprehensions are awesome.
The loops could be replaced by list comprehensions
(with the help functions), for example:

def read_int():
    while True:
        try:
            return int(raw_input('Enter an integer: '))
        except ValueError:
            print 'That was not an integer!'

numbers = [read_int() for _ in range(10)]

odd_numbers = [item for item in numbers if item % 2]

if odd_numbers:
    print 'The largest odd number entered was {}.'.format(max(odd_numbers))
else:
    print 'No odd number was entered.'


Prefer .format(...) for formatting

Instead of formatting with %,
the new preferred way is using .format(...):

print 'The largest odd number entered was {}.'.format(max(odd_numbers))


Notice that there's no need to call str(...) when using this style.

Readability

This statement would have been better on a single line:


print 'The largest odd number entered was %s.' % str(max(
        odd_numbers))