方法一:使用python的内置函数max
def custom1_max(a,b,c):
if isinstance(a,(int,float)) and isinstance(b,(int,float)) and isinstance(c,(int,float)):
print("max_num1=%s" %max(a,b,c))
else:
print("传入的三个数其中有不是数字,不能进行求最大!")
custom1_max(1,10.5,5) #max_num1=10.5
custom1_max(1,5,5) #max_num1=5
custom1_max("1",10.5,5) #传入的三个数其中有不是数字,不能进行求最大!
方法二:两两进行比较
def custom2_max(a,b,c):
if isinstance(a,(int,float)) and isinstance(b,(int,float)) and isinstance(c,(int,float)):
if a<b:
a,b=b,a
if a<c:
a,c=c,a
if b<c:
b,c=c,b
print("max_num2=%s" %a) #注意最大值是a
else:
print("传入的三个数其中有不是数字,不能进行求最大!")
custom2_max(1,5,4) #max_num2=5
custom2_max(1,2,2) #max_num2=2
custom1_max("1",10.5,5) #传入的三个数其中有不是数字,不能进行求最大!