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>
Written by Abhinav Mishra
Related protips
1 Response
Why do you coerce them to integers? Then max(1, 1.5) will return 1.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#