Skip to main content
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

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 my follow-up code on feedback from Find the largest odd number (follow-up code)Find the largest odd number (follow-up code)

This time I'm trying to achieve the same result with nested functions. I need your comments please. Also, please note that I'm working through a book and it's meant to be used with Python 2.x

def find_largest_odd():
    numbers_entered = []
    
    def get_ten_ints():
        while len(numbers_entered) < 10:
            try:
                number = int(raw_input('Enter an integer: '))
                numbers_entered.append(number)
            except ValueError:
                print 'That was not an integer!'
    
    get_ten_ints()
    
    try:
        largest_odd_number = max(item for item in numbers_entered if item % 2)
        return 'The largest odd number entered was {}.'.format(largest_odd_number)
    except ValueError:
        return 'No odd number was entered.'

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 my follow-up code on feedback from Find the largest odd number (follow-up code)

This time I'm trying to achieve the same result with nested functions. I need your comments please. Also, please note that I'm working through a book and it's meant to be used with Python 2.x

def find_largest_odd():
    numbers_entered = []
    
    def get_ten_ints():
        while len(numbers_entered) < 10:
            try:
                number = int(raw_input('Enter an integer: '))
                numbers_entered.append(number)
            except ValueError:
                print 'That was not an integer!'
    
    get_ten_ints()
    
    try:
        largest_odd_number = max(item for item in numbers_entered if item % 2)
        return 'The largest odd number entered was {}.'.format(largest_odd_number)
    except ValueError:
        return 'No odd number was entered.'

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 my follow-up code on feedback from Find the largest odd number (follow-up code)

This time I'm trying to achieve the same result with nested functions. I need your comments please. Also, please note that I'm working through a book and it's meant to be used with Python 2.x

def find_largest_odd():
    numbers_entered = []
    
    def get_ten_ints():
        while len(numbers_entered) < 10:
            try:
                number = int(raw_input('Enter an integer: '))
                numbers_entered.append(number)
            except ValueError:
                print 'That was not an integer!'
    
    get_ten_ints()
    
    try:
        largest_odd_number = max(item for item in numbers_entered if item % 2)
        return 'The largest odd number entered was {}.'.format(largest_odd_number)
    except ValueError:
        return 'No odd number was entered.'
added 8 characters in body
Source Link
srig
  • 183
  • 1
  • 7

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 my follow-up code on feedback from Find the largest odd number (follow-up code)

This time I'm trying to achieve the same result with nested functions. I need your comments please. Also, please note that I'm working through a book and it's meant to be used with Python 2.x

def find_largest_odd():
    numbers_entered = []
    
    def get_ten_ints():
        while len(numbers_entered) < 10:
            try:
                number = int(raw_input('Enter an integer: '))
                numbers_entered.append(number)
            except ValueError:
                print 'That was not an integer!'
    
    get_ten_ints()
    
    odd_numberstry:
 = [item for item in numbers_entered if item %largest_odd_number 2]
= max(item for item 
 in numbers_entered if item if% odd_numbers:2)
        return 'The largest odd number entered was {}.'.format(max(odd_numbers)largest_odd_number)
    elseexcept ValueError:
        return 'No odd number was entered.'

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 my follow-up code on feedback from Find the largest odd number (follow-up code)

This time I'm trying to achieve the same result with nested functions. I need your comments please. Also, please note that I'm working through a book and it's meant to be used with Python 2.x

def find_largest_odd():
    numbers_entered = []
    
    def get_ten_ints():
        while len(numbers_entered) < 10:
            try:
                number = int(raw_input('Enter an integer: '))
                numbers_entered.append(number)
            except ValueError:
                print 'That was not an integer!'
    
    get_ten_ints()
    
    odd_numbers = [item for item in numbers_entered if item % 2]
    
     if odd_numbers:
        return 'The largest odd number entered was {}.'.format(max(odd_numbers))
    else:
        return 'No odd number was entered.'

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 my follow-up code on feedback from Find the largest odd number (follow-up code)

This time I'm trying to achieve the same result with nested functions. I need your comments please. Also, please note that I'm working through a book and it's meant to be used with Python 2.x

def find_largest_odd():
    numbers_entered = []
    
    def get_ten_ints():
        while len(numbers_entered) < 10:
            try:
                number = int(raw_input('Enter an integer: '))
                numbers_entered.append(number)
            except ValueError:
                print 'That was not an integer!'
    
    get_ten_ints()
    
    try:
        largest_odd_number = max(item for item in numbers_entered if item % 2)
        return 'The largest odd number entered was {}.'.format(largest_odd_number)
    except ValueError:
        return 'No odd number was entered.'
edited title
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481

The largest odd number (follow-up code using nested functions)

Source Link
srig
  • 183
  • 1
  • 7
Loading