/
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. 17.10.2022 at 12:31 pm / AI Art Is Real Art
  2. 10.07.2021 at 01:46 pm / Plants Are Maths
  3. 03.07.2021 at 10:31 am / Learning Forever
  4. 23.02.2021 at 09:34 pm / Counsel Citing Adverse Authorities
  5. 11.02.2021 at 12:56 am / 46 Simple Python Exercises/#01
  6. 20.08.2020 at 08:59 pm / A Case for Legalese (Or Not)
  7. 10.01.2020 at 10:40 am / Learned Lumber
  8. 31.12.2019 at 09:03 pm / Reflections - 43 Things I Learned or Did In 2019
  9. 16.09.2019 at 10:32 am / Legal Practice & Taking From Software Best Practices
© Wan Zafran. See disclaimer.