我在尝试使用函数来计算列表的最小值、最大值和和时遇到了一些问题。 列表是随机生成的,用户可以选择列表中有多少个值。 有人能帮我弄清楚如何使用tempList和tempdim(临时维度)创建函数吗?在
我有一个代码来制作维度和随机列表,我觉得我有一个很好的程序结构。。我就是不知道怎么做函数代码。在
这就是我目前所拥有的。。。在
import random
MINRAND = 1
MAXRAND = 1000
def main():
dimensions = int(input("How large do you want your square 2D array? "))
numbers = [[] for i in range(dimensions)]
generateList(numbers, dimensions)
printList(numbers, dimensions)
print("2-D List Highest Element is: ", findHighest(tempList))
print("2-D List Lowest Element is: ", findLowest(tempList))
print("2-D List Sum is: ", sum2Dlist(tempList))
def findHighest(tempList, tempdim):
def findLowest(tempList, tempdim):
def sum2Dlist(tempList, tempdim):
def generateList(tempList, tempdim):
for row in range(tempdim):
for col in range(tempdim):
tempList[row].append(random.randint(MINRAND, MAXRAND))
def printList(templist, tempdim):
for row in range(tempdim):
for col in range(tempdim):
print(format(templist[row][col], '6d'), end=" ")
print()
# Call the main function
main()
太感谢你了!!在
目前没有回答
相关问题 更多 >
编程相关推荐