/
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. 11.06.2022 at 11:30 am / Salted Correspondences
  2. 30.04.2022 at 10:36 am / Masters of A Fraction of A Dot
  3. 10.01.2020 at 10:40 am / Learned Lumber
  4. 31.12.2018 at 06:23 pm / Why Plain Text
  5. 15.12.2017 at 12:00 am / The Breakings of Julia
  6. 24.10.2015 at 12:00 am / Salomon v Salomon is Antiquated
  7. 28.06.2015 at 12:00 am / No Social Transformation Without Representation
  8. 17.12.2014 at 12:00 am / 午・午年
  9. 03.01.2014 at 12:00 am / Write With Vigour
  10. 02.04.2012 at 12:00 am / Abstract Wall Painting
© Wan Zafran. See disclaimer.