[英]Function to find maximum of 3 variables isn't returning anything
我的问题是什么? 我跑得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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.