I'd like to create a function that will print the max value within a list of numbers.
Asked
Active
Viewed 2,182 times
-8
-
Are you familiar with the built-in `max` function? – Yoel Oct 05 '14 at 01:18
-
I think you should do your homeworks on your own, if you ever want to learn something. – m.wasowski Oct 05 '14 at 01:22
1 Answers
-1
I dont know python but the pseudocode would look something like this
max = –2147483648
for each integer n in collection
if n > max
max = n
It loops through every number in a collection. If the number (n) is bigger than the previous maximum, the maximum is set to be equal to n.

Tokfrans
- 1,939
- 2
- 24
- 56
-
-
-
@m.wasowski I'm sorry if I'm not the best programmer in the world. But I'm pretty sure the OP got what he was asking for. – Tokfrans Oct 05 '14 at 01:26
-
3he should do this on his own. And general algorithm is: 1) if collection is empty, return None or raise error. 2) max := first element 3) ... then your code X)... return max – m.wasowski Oct 05 '14 at 01:29
-
@m.wasowski Very well, then. Glad you wanted to help him some more =) – Tokfrans Oct 05 '14 at 01:30
-
2Integers in Python [can be of arbitrary size](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) - any solution which assumes they're limited to 32 bits will fail for some valid inputs. – Zero Piraeus Oct 05 '14 at 02:18
-
2... and in any case, the question specifies "numbers" rather than "integers". What happens with the list `[-1.0e10, -1.0e12, -1.0e11]`? – Zero Piraeus Oct 05 '14 at 02:24