You are viewing a single comment's thread from:

RE: 5.12 Maximum of Two Values - Python

in #programming8 years ago (edited)

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.
Sort:  

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.17
TRX 0.15
JST 0.028
BTC 59911.66
ETH 2306.14
USDT 1.00
SBD 2.49