/
11.02.2021 at 12:56 am
Cuttings

46 Simple Python Exercises/#01

Define a function max() that takes two numbers as arguments and returns the largest of them.

Problem

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.)

Solution

    def new_max(a, b):

    assert b != a, "Values are the same."
    if a > b:
        return a
    elif b > a:
        return b

    print(new_max(46, 46.5))

Filed under:
#
#
Words: 98 words approx.
Time to read: 0.39 mins (at 250 wpm)
Keywords:
, , , , , , , , ,

Potentially related: 46 Simple Python Exercises/#02

Other suggested posts

  1. 15.06.2022 at 01:04 am / Prepackaged Thought Cassettes
  2. 21.07.2021 at 07:46 am / Basis for Base64
  3. 23.02.2021 at 09:34 pm / Counsel Citing Adverse Authorities
  4. 12.03.2016 at 12:00 am / Transcript of Tifa Funk - Interlude Solo (Tifa's Theme by Tetrimino)
  5. 05.03.2016 at 12:00 am / Rather Be (Alexa Goddard's Version)
  6. 16.10.2015 at 12:00 am / Statements Without Data
  7. 06.10.2015 at 08:02 am / Subservient/Servile Written Malay
  8. 18.06.2015 at 12:00 am / Crisp Tweets
  9. 18.05.2015 at 12:00 am / Indian Judicial Writing
  10. 19.03.2012 at 12:00 am / Lush Exoplanets
© Wan Zafran. See disclaimer.