# Max of Three¶

In [13]:
from random import sample

In [7]:
def max1(x1, x2, x3):
if x=1 >= x2 and x1 >= x3:
_max = x1
elif x2 >= x1 and x2 >= x3:
_max = x2
else:
_max = x3

return _max

In [ ]:
def max2(x1, x2, x3):
if x1 >= x2:
if x1 >= x3:
_max = x1
else:
_max = x3
else:  # x2 >= x1
if x2 >= x3:
_max = x2
else:
_max = x3

return _max

In [ ]:
def max2a(x1, x2, x3, x4):
if x1 >= x2:
if x1 >= x3:
if x1 >= x4:
_max = x1
else:
_max = x4
else:
_max = x3
else:  # x2 >= x1
if x2 >= x3:
_max = x2
else:
_max = x3

return _max

In [ ]:
def max3(x1, x2, x3):
"""Sequential check of max of three"""
_max = x1

if x2 >= _max:
_max = x2

if x3 >= _max:
_max = x3

In [10]:
def max4(nums):
_max = nums[0]  # Assume the first value is the max

for i in range(1, len(nums)):
if nums[i] >= _max:
_max = nums[i]

return _max

In [24]:
def main():
#x1, x2, x3 = eval(input("Please enter three values:"))
#_max = max1(x1, x2, x3)
#numbers = [x1, x2, x3]

numbers = sample(range(0, 1_000_000), k=100_000)
#print(numbers)

_max = max4(numbers)

print("\nThe largest value is {0}.".format(_max))

In [25]:
main()

The largest value is 999996.