简体   繁体   English

为什么不打印这些功能?

[英]Why aren't these functions printing?

I'm having trouble with some code I wrote in the past. 我过去写的一些代码有麻烦。 Is there a reason these functions aren't printing anything in terminal? 这些功能没有在终端上打印任何内容是有原因的吗?

def count_evens_2d():
    count = 0
    xss = [[10,13,17],[3,6,1],[13,11,12]]   
    for i in xss:
        for j in i:
            if j%2 == 0:
                count += 1
    print(count)

def min_2d():
    xss = [[10,13,17],[3,6,1],[13,11,12]]
    lowest_val = None
    for i in xss:
        for j in i:
            if lowest_val is None or j < lowest_val:
                lowest_val = j
                print(lowest_val)

My logic seems to be correct in the first function I'm attempting to count all even numbers in that list of lists and in the second function I'm trying to find the minimum value in the list of lists. 我的逻辑似乎在第一个函数中试图对列表列表中的所有偶数进行计数是正确的,而在第二个函数中,我试图在列表中找到最小值。 Thanks to anyone who can help 感谢任何能提供帮助的人

You should call them in your code as mentioned. 您应该按照上述在代码中调用它们。 Eg: 例如:

def count_evens_2d():
    count = 0
    xss = [[10,13,17],[3,6,1],[13,11,12]]
    for i in xss:
        for j in i:
            if j%2 == 0:
                count += 1
    print(count)

def min_2d():
    xss = [[10,13,17],[3,6,1],[13,11,12]]
    lowest_val = None
    for i in xss:
        for j in i:
            if lowest_val is None or j < lowest_val:
                lowest_val = j
                print(lowest_val)


count_evens_2d()
min_2d()

I tried it and the printed values seem correct for the given list of lists. 我尝试了一下,对于给定的列表列表,打印的值似乎正确。

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

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