我的问题是什么?我跑biggest(10,5,6)
了,但它什么也没返回。
def biggest(a,y,z):
Max=a
if y>Max:
Max=y
if z>Max:
Max=z
return Max
>>> max(2, 3, 5)
5
>>> help(max)
关于内置模块内置函数 max 的帮助:
max(...)
max(iterable[, key=func]) -> value
max(a, b, c, ...[, key=func]) -> value
With a single iterable argument, return its largest item.
With two or more arguments, return the largest argument.
(END)
def max_of_three(x,y,z):
Max = x
if y > Max:
Max = y
if z > Max:
Max =z
print Max
max_of_three(3,4,2)
打印 4
最好在 python 中使用“max”函数,max 最好的一点是,它不限于 3 或 4 个参数。
"""
max(iterable, *[, default=obj, key=func]) -> value
max(arg1, arg2, *args, *[, key=func]) -> value
With a single iterable argument, return its biggest item. The
default keyword-only argument specifies an object to return if
the provided iterable is empty.
With two or more arguments, return the largest argument.
"""
max_value = max(1, 2, 3)
print(max_value) # will return 3
x = float(input("Enter the first number: "))
y = float(input("Enter the second number: "))
z = float(input("Enter the third number: "))
if x >= y and x >= z:
maximum = x
elif y >= z and y >= x:
maximum = y
else:
maximum = z
print("The maximum no. b/w : ", x, ",", y, "and", z, "is", maximum)
def findMax(a, b,c)
return max(a, b,c)
print(findMax(6, 9, -5)
我会把它贴在这里,以防一些新的 Python 学生来到这里。
def biggest (a, b, c):
imax = a
if (b > imax) and (b > c):
imax = b
elif (c > imax):
imax = c
return imax
#to test
print (biggest(5,6,7))
if x>y>z:
print ("max number is x : ",x)
if z>y :
print ("max number is z : ",z)
if y>z :
print ("max number is y : ",y)