我编写了一个简单的 map() 函数,它遍历一个列表并打印列表中尽可能多的“*”。我看到我的代码有一个小问题,我'None'
在输出中看到了一个额外的问题。有人可以帮我调试这个问题吗?
Problem Statement:
-----------------
Define a procedure histogram() that takes a list of integers and prints a
histogram to the screen. For example, histogram([4, 9, 7]) should print the
following:
****
*********
*******
源代码
def print_asterisks(num):
print ''.join('*' for i in xrange(num))
def histogram(s):
map(print_asterisks, s)
def main():
# Test inputs
print histogram([4,7,5])
if __name__ == "__main__":
import sys
sys.exit(main())
输出
****
*******
*****
None