/
11.02.2021 at 12:56 am
Cuttings

46 Simple Python Exercises/#01

Largest number selector.

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

Code
                        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: 7 words approx.
Time to read: 0.03 mins (at 250 wpm)
Keywords:
, , , , ,

Other suggested posts

  1. 16.12.2024 at 02:42 pm / Vim As A Language
  2. 29.03.2023 at 09:38 am / Moving Away from Todoist - to Taskwarrior, SSH & Dropbox - Part 1
  3. 04.01.2023 at 10:52 pm / Newton's Commonplace Beginnings
  4. 03.07.2022 at 05:15 pm / The Unpreparedness Apology
  5. 10.07.2021 at 01:46 pm / Plants Are Maths
  6. 20.08.2020 at 08:59 pm / A Case for Legalese (Or Not)
  7. 14.01.2020 at 01:24 pm / Third Time's A Charm
  8. 23.08.2018 at 09:53 am / Nostalgic Non-Memories
  9. 25.09.2010 at 12:00 am / 汗牛充棟
  10. 22.08.2010 at 12:00 am / 柿が赤くなると医者が青くなる
© Wan Zafran. See disclaimer.