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.
This is a follow-up code on feedback from Find the largest odd number
This time I've taken care of a bug related to the number of integers entered and tried to handle invalid input if any. Please let me know if the code still can be tidied up in any way. I'm a beginner programmer.
print "You'll be asked to enter 10 integers."
print 'The program will look for odd numbers, if any.'
print 'Then, it will print the largest odd number.'
print 'Press Enter to start.'
raw_input('-> ')
numbers_entered = []
while True:
try:
number = int(raw_input('Enter an integer: '))
numbers_entered.append(number)
except ValueError:
print 'That was not an integer.'
if len(numbers_entered) == 10:
break
odd_numbers = [item for item in numbers_entered if item % 2 == 1]
if odd_numbers:
print 'The largest odd number entered was {}.'.format(max(odd_numbers))
else:
print 'No odd number was entered.'
while len(numbers_entered) <= 10)
. \$\endgroup\$