/
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. 29.03.2023 at 10:57 am / Moving Away from Todoist - to Taskwarrior, SSH & Dropbox - Part 2
  2. 15.06.2022 at 01:04 am / Prepackaged Thought Cassettes
  3. 29.09.2020 at 12:24 pm / Rays of Circumstance
  4. 13.02.2020 at 10:29 am / The Code Language Lawyers
  5. 14.12.2018 at 03:09 pm / Recursion, Succinctly Put
  6. 23.08.2018 at 09:53 am / Nostalgic Non-Memories
  7. 12.03.2016 at 12:00 am / Transcript of Tifa Funk - Interlude Solo (Tifa's Theme by Tetrimino)
  8. 12.06.2015 at 12:00 am / He Conquers Who Endures
  9. 16.02.2014 at 12:00 am / Don't Care Too Much About Gear
  10. 02.04.2012 at 12:00 am / Abstract Wall Painting
© Wan Zafran. See disclaimer.