/
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. 02.07.2021 at 09:51 am / The Problem With New Tools
  2. 27.08.2020 at 09:33 pm / Write Like You Play Tetris
  3. 04.06.2020 at 05:25 pm / Music and Neural Pathways
  4. 03.01.2020 at 10:46 am / Git for Legal Practice
  5. 22.07.2015 at 12:00 am / Fair Judges of Fair Play
  6. 18.06.2015 at 12:00 am / Crisp Tweets
  7. 18.05.2015 at 12:00 am / Indian Judicial Writing
  8. 07.07.2014 at 12:00 am / If I Cannot Strengthen Our Bench
  9. 05.07.2014 at 12:00 am / Jack Hamm on (Artistic) Practice
© Wan Zafran. See disclaimer.