/
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. 03.07.2022 at 05:15 pm / The Unpreparedness Apology
  2. 19.02.2020 at 10:25 am / STEM, STEAM and Art
  3. 02.01.2018 at 12:00 am / Genuinely Technical Modesty
  4. 17.12.2017 at 12:00 am / To Know C
  5. 15.12.2017 at 12:00 am / The Breakings of Julia
  6. 11.12.2013 at 12:00 am / Lighting Wizardry
  7. 29.11.2013 at 12:01 am / 美しい - Beautifully Woolly
  8. 04.07.2012 at 12:00 am / When To Not Use Data Structures/Algorithms
  9. 21.04.2012 at 12:00 am / Cinematic Mass Effect
  10. 22.08.2010 at 12:00 am / 柿が赤くなると医者が青くなる
© Wan Zafran. See disclaimer.