/
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. 01.01.2025 at 04:44 pm / The Core Apple Appeal
  2. 02.04.2023 at 01:03 pm / Witching May Die, But Not Litigation
  3. 11.06.2022 at 09:09 pm / 大蛇に嫁いだ娘 - The Girl Married to the Giant Serpent
  4. 27.06.2021 at 12:49 pm / Eloquent Javascript / Chapter 2, Exercise 03
  5. 12.02.2021 at 12:55 am / 46 Simple Python Exercises/#10
  6. 22.08.2020 at 05:49 pm / Decoding Code Specimens
  7. 31.12.2019 at 09:03 pm / Reflections - 43 Things I Learned or Did In 2019
  8. 07.10.2019 at 11:22 am / 3D & 2D - The Demarcation
  9. 19.08.2018 at 02:13 pm / Saunter Not
  10. 15.08.2010 at 12:00 am / 海老
© Wan Zafran. See disclaimer.