How do I find the maximum of 2 numbers?

后端 未结 10 1957
借酒劲吻你
借酒劲吻你 2020-12-03 02:22

How to find the maximum of 2 numbers?

value = -9999
run = problem.getscore()

I need to compare the 2 values i.e value and

相关标签:
10条回答
  • 2020-12-03 03:03

    You can use max(value, run)

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

    0 讨论(0)
  • 2020-12-03 03:07

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

    The answer is: max() !

    0 讨论(0)
  • 2020-12-03 03:07

    You could also achieve the same result by using a Conditional Expression:

    maxnum = run if run > value else value
    

    a bit more flexible than max but admittedly longer to type.

    0 讨论(0)
  • 2020-12-03 03:07

    I noticed that if you have divisions it rounds off to integer, it would be better to use:

    c=float(max(a1,...,an))/b

    Sorry for the late post!

    0 讨论(0)
提交回复
热议问题