Find out the biggest odd number from three arguments in a function [Python] -
i need write function print biggest odd number 3 input arguments.
here code.
def oddn(x,y,z): odd_number_keeper = [] item in x,y,z: global odd_number_keeper if item % 2==1: odd_number_keeper = [item] return max(odd_number_keeper) else: print 'no odd number found'
my codes seem not working. ideas how can modify code?
a few changes needed:
def oddn(x,y,z): odd_number_keeper = [] item in [x,y,z]: if item % 2==1: odd_number_keeper.append(item) if not odd_number_keeper: print 'no odd number found' return return max(odd_number_keeper)
iterate on values x
, y
, z
, add odd numbers odd_number_keeper
. if there numbers return max()
of elements in list of odd numbers. if there no odd numbers print message , return (without result, there no number return).
Comments
Post a Comment