tags:

views:

218

answers:

6

How to find the maximum of 2 numbers?

value = -9999
run = problem.getscore()

I need to compare the 2 values i.e value and run and find the maximum of 2. I need some python function to operate it?

+3  A: 

max(number_one, number_two)

dave
Just `max(number_one, number_two)`. The `[]`'s don't add anything useful.
Thomas Wouters
yeah, those were to show that you should just use to arbitrary numbers, but I can see how that would be confusing
dave
+8  A: 

max()

Ignacio Vazquez-Abrams
+1 for typing faster than me.
Ashish
+2  A: 

You can use max(value, run)

The function max takes any number of arguments, or (alternatively) an iterable, and returns the maximum value.

Chris B.
+1  A: 
max(value,run)

should do it.

Tim Pietzcker
+3  A: 

Use the builtin function max.

Example: max(2, 4) returns 4.

just for giggles, there's a min as well...should you need it. :P

townsean
A: 

Just for the fun of it, after the party has finished and the horse bolted.

The answer is: max() !

Muhammad Alkarouri