/
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.01.2024 at 08:16 pm / Go Interfaces - By Witcher-Like Metaphors
  2. 01.04.2023 at 11:27 am / Search Notes Fast: With Taskwarrior, jq & ripgrep
  3. 25.08.2020 at 08:42 am / Triple Buffered Painters
  4. 16.09.2019 at 10:32 am / Legal Practice & Taking From Software Best Practices
  5. 23.08.2018 at 01:33 am / Darwin's Details
  6. 31.05.2015 at 12:00 am / Judges Should Not Fear Criticism
  7. 03.07.2013 at 12:00 am / Craft Versus Discipline
  8. 19.03.2012 at 12:00 am / Lush Exoplanets
  9. 26.08.2010 at 12:00 am /
  10. 20.08.2010 at 12:00 am / 堰かれて募る恋の情
© Wan Zafran. See disclaimer.