How is the max( ) function used?

Question

How is the max( ) function used?

Answer

We start the exercise with an empty variable called maximum that we want to assign a value to. The value should use the max() function to return the largest number in the set of arguments you provide to it.
For example, if we did my_var = max(1, 2, 3), the value stored in my_var would be 3!
If you think you’ve done this correctly and still can’t pass the exercise, please try the following:

  1. Try using Chrome, as it’s typically the most reliable browser.
  2. Clear your browser cache and press Ctrl + F5 (Windows) or Cmd + Shift + R (Mac)
  3. If none of that works, please check out our [official troubleshooting guide]
    (Troubleshooting Guide)
1 Like

Why does 08 or 09 not work in max function?

maximum = max(12, 34, 53, 05, 06, 07, 08, 09, 013, 38.3, 53.1)

Throws an error:
SyntaxError: invalid token

Hello :pig:

I am not sure but I think 0+number represents octal numbers in python 2.x
The octal number system has 8 digits (0, 1, 2, 3, 4, 5, 6, 7) and no more. The number 08 and 09 have no meaning. The representation of the numbers 8 and 9 in octal number are : 0o10 and 0o11.

In Python 3, the syntax for octals changed to this: 0o0 to 0o7

3 Likes

and now you know, you are…

>>> int('0o111', 8)
73
>>> 
    8^2 + 8^1 + 8^0
     64 +  8  +  1    => 73
>>> max(12, 34, 53, 5, 6, 7, int(oct(8), 8), int(oct(9), 8), int('0o13', 8), 38.3, 53.1)
53.1
>>> 
3 Likes