/
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. 10.06.2022 at 07:44 pm / Teach Thy Tongue to Say: 'I Do Not Know'
  2. 11.01.2019 at 06:39 pm / Clarity of Liskov
  3. 11.07.2016 at 12:00 am / SublimeREPL's Slow Printing/Freezing - A Solution
  4. 03.01.2016 at 12:00 am / Creators And Their Gems (Polished or Otherwise)
  5. 14.06.2015 at 12:00 am / Just the Two of Us (6-Bar Guitar/Sax Copy)
  6. 17.01.2015 at 12:00 am / Grandma - Guitar Arrangement (NieR Gestalt)
  7. 16.01.2015 at 12:00 am / Ih Ah! (Devin Townsend)
  8. 28.11.2013 at 12:00 am / ケチ - Scroogean Niggardliness
  9. 26.03.2012 at 12:00 am / Apricot Orange Sunsets
  10. 20.08.2010 at 12:00 am / 堰かれて募る恋の情
© Wan Zafran. See disclaimer.