/
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. 03.07.2022 at 05:15 pm / The Unpreparedness Apology
  3. 11.06.2022 at 09:09 pm / 大蛇に嫁いだ娘 - The Girl Married to the Giant Serpent
  4. 06.06.2022 at 12:26 pm / To Teach or To Paint
  5. 10.07.2021 at 01:46 pm / Plants Are Maths
  6. 12.03.2016 at 12:00 am / Transcript of Tifa Funk - Interlude Solo (Tifa's Theme by Tetrimino)
  7. 06.10.2015 at 08:02 am / Subservient/Servile Written Malay
  8. 23.07.2015 at 12:00 am / The Line Between Gifts and Bribes
  9. 18.07.2014 at 12:00 am / Keep Learning Songs
  10. 16.08.2010 at 12:00 am / You Have Reason
© Wan Zafran. See disclaimer.