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 > largestOddNumber:
largestOddNumber = number
print largestOddNumber or 'No odd number was entered.'
max(number for number in input_list if number % 2 == 1)
. Almost as readable as plain English, compact, easy to maintain and reason about, and probably pretty fast \$\endgroup\$