Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.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 如何在不使用max()的情况下查找数组中的最高整数_Python_Python 3.x - Fatal编程技术网

Python 如何在不使用max()的情况下查找数组中的最高整数

Python 如何在不使用max()的情况下查找数组中的最高整数,python,python-3.x,Python,Python 3.x,我需要找到数组中的最大数,但我在这样做时遇到了问题 有帮助的代码如下: def printing(test1Array,test2Array,test3Array,nameArray,totalArray): for i in range(0,3): print(nameArray[i], "scored", totalArray[i] ,"in total") print("The average for this person was" , tota

我需要找到数组中的最大数,但我在这样做时遇到了问题

有帮助的代码如下:

def printing(test1Array,test2Array,test3Array,nameArray,totalArray):
    for i in range(0,3):
        print(nameArray[i], "scored", totalArray[i] ,"in total")
        print("The  average for this person was" , totalArray[i]/3)
    a = sum(totalArray)
    a = a/9
    print("The class average was" , a)
highest(test1Array,test2Array,test3Array,nameArray,totalArray)

def highest(test1Array,test2Array,test3Array,nameArray,totalArray):
    bestPerson = totalArray[i]
如果你想让我添加更多的代码,请这样说。 最后的最高功能就是我需要的帮助。
谢谢。

假设您有一个列表

x = [1, 25, 2]
你能行

y = sorted(x)
print(y)
>>> [1,2,25]
为了得到max

y[-1]

PS:我的是一个通用的解决方案,你可以使用它来达到你的效果。但是有一个问题,为什么不使用max()?

如果不需要任何内置函数,请尝试以下代码:

def highest(test1Array,test2Array,test3Array,nameArray,totalArray):
    bestPerson = totalArray[0]
    for i in totalArray:
        bestPerson = i if i>bestPerson else bestPerson
    return bestPerson
虽然我不知道为什么要将其他数组传递给
最高的
,但假设它是一个函数,用于返回
totalArray中的最高值

def highest(a):
  max = a[0]
  for i in a:
    if i>max:
        max = i
  print max


highest([1,2,3,10,5])
o/p
你可以这样试试

a = [1, 23, 4]
max_value = 0
for i in a:
    if i > max_value:
        max_value = i
print max_value

如果您想使用
python3
,那么可以使用内置的
max

array = [1, 3, 4, 12, 4, 7]
    def get_maxnum(given_array):
    maxnum = max(given_array)
    return maxnum
print("max num is ",get_maxnum(array))
产出:12


y[-1]
y[len(y)-1]
@julivico谢谢,我从来没有试过。感谢您的指导:P人为的“不使用max()”限制的原因是什么?尽管ravindar已经回答了您标题中的字面问题,但您发布的代码似乎与此无关。你能用一些预期的输入和输出补充你的问题吗?将为
testnArray
nameArray
totalArray
分配哪些类型的值?您希望您的程序如何处理这些值?