Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python编写代码,这样它就可以在不使用输入或打印以及使用def、if和ele的情况下告诉我模式_Python_Python 2.7_Python 3.x_Mean_Median - Fatal编程技术网

如何使用python编写代码,这样它就可以在不使用输入或打印以及使用def、if和ele的情况下告诉我模式

如何使用python编写代码,这样它就可以在不使用输入或打印以及使用def、if和ele的情况下告诉我模式,python,python-2.7,python-3.x,mean,median,Python,Python 2.7,Python 3.x,Mean,Median,我的代码到目前为止,但我在测试时遇到了一个错误: # without using any collection data types like list or set, this # function determines which value appears the most often and returns it. def mode3(a, b, c): # starting value for variable ans. Replace it with the #

我的代码到目前为止,但我在测试时遇到了一个错误:

# without using any collection data types like list or set, this
# function determines which value appears the most often and returns it.

def mode3(a, b, c):

    # starting value for variable ans. Replace it with the
    # actual answer before reaching the return stmt.if int(value) < 0 :


    ans = None
if int(mode3(a, a, b)):
    ans = "a"
if int(mode3(a, b, b)):
    ans = "b"
if int(mode3(a, c, c)):
    ans = "c"
else:
    return ans
#在不使用任何收集数据类型(如列表或集合)的情况下
#函数确定哪个值最常出现并返回它。
def模式3(a、b、c):
#变量ans的起始值。将其替换为
#到达返回stmt之前的实际答案。如果int(值)<0:
ans=无
如果int(模式3(a、a、b)):
ans=“a”
如果int(模式3(a、b、b)):
ans=“b”
如果int(模式3(a、c、c)):
ans=“c”
其他:
返回ans

我想你要找的是

def mode3(a, b, c):
    if a == b or a == c:
        return a
    elif b == c:
        return b
    else:
        return None
你可以像这样测试它

mode3(1, 1, 1)     # => 1
mode3(1, 1, 2)     # => 1
mode3(1, 2, 1)     # => 1
mode3(2, 1, 1)     # => 1
mode3(1, 2, 3)     # => None

为了获得有用的帮助,你应该在这里输入你的代码,而不是粘贴代码的链接图像。我强烈建议你在因质量差而被否决之前编辑你的问题