繁体   English   中英

如何将 3 个数字与在 Python 中仅采用 2 个变量的函数与我编写的代码进行比较

[英]How do I compare 3 numbers with a function that takes only 2 variables in Python with a code that I have written

我在 Python Jupyter 中编写了一个代码,其中包含以下说明:编写一个函数,该函数将始终返回 2 个不等数中较大的一个(不要使用 max 或任何内置函数),将其命名为show_max

def show_max(x,y):
if(x == y):
    r = ("Both the numbers are equal")
elif(x > y):
    r = (f"{x} is the maximum number")
else:
    r = (f"{y} is the maximum number")
return(r)

此后,我必须按照以下说明进行编码:使用show_max函数编写代码以找到 3 个不等数中最大的一个

我无法编码第二部分。 任何人都可以帮忙。 谢谢!!!

我想你也可以使用这种方法:

def show_max(x,y,z):
    nums = [x,y,z]
    nums.sort()
    return f"{nums[-1]} is the maximum number"

不需要比较。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM