5.12 Maximum of Two Values - Python

in #programming8 years ago (edited)

Hello Everyone! Ultimately, we would use the predefined function max() to solve a question like this, but we recreated the wheel here to see a variation of the max() function! :) Thanks to @chaten for hinting at this :)

Starting out with Python, Third Edition, Tony Gaddis
Chapter 5
Programming Challenges

12 ) Maximum of Two Values

Starting out with Python. Third Edition. Tony gaddis.

Happy Steeming Everyone! :)

Sort:  

2 points:

  • Your program shadows an inbuilt function, you redefine max, which is defined by Python itself, this is a very bad thing to do, and should not be in the tutorial.
  • This can be done in one line with said inbuilt function, max
    max(1,12) will return 12 in the Python console, so you could just have
    max(FirstNumber, SecondNumber)

Things to take away from this:

  • Do not shadow or any decent programmer will cry their guts out.
  • Keep It Simple Stupid (KISS), and use inbuilt functions.

Very well said! Thank you :) As you may have seen from the description, this is a question from a book, Starting out with Python that only allows you to include knowledge and concept from a particular chapter. The author certainly knows there's a predefined max function. But as a "programming challenge" and a learning process, the author was explicit and wanted us to first create the max function or at least a variation of it, to see how it works first and to see the inner working of it instead of just relying on it. This was a test, so students can appreciate predefined functions even better by first understanding the concept of creating functions.

I understand programmers wouldn't normally do that and I 100% agree :) If I was creating a program for production, I would use the predefined max() but again this was only to recreate the wheel, not for a bad purpose but for learning purposes. You're right! I should at least point out in the description, there's a predefined function max() ( Done! :) see description ), for those who don't know, but the students using the book definitely would know about it if they read the book.

Thank you so much @chaten for your contribution. Viewers will definitely learn from your comment. Please keep them coming :)

Coin Marketplace

STEEM 0.16
TRX 0.13
JST 0.027
BTC 58470.49
ETH 2617.16
USDT 1.00
SBD 2.39