[フレーム]
Last Updated: February 25, 2016
·
1.816K
· abhinavmishra

Learn Python by example- 001

Define a function max() that takes two numbers as arguments and returns the largest of them. Use the if-then-else construct available in Python.
(It is true that Python has the max() function built in, but writing it yourself is nevertheless a good exercise.)


 def my_max(a, b):
 if int(a) >= int(b):
 return a;
 else:
 return b;

if __name__ == '__main__':
 print my_max(1,3)


</pre></code>

1 Response
Add your response

Why do you coerce them to integers? Then max(1, 1.5) will return 1.

over 1 year ago ·

AltStyle によって変換されたページ (->オリジナル) /