注册 登录
编程论坛 Python论坛

新手求助一个关于define function的问题

GodBlessMe 发布于 2012-08-27 13:39, 1430 次点击
Implement a Python function called validate_image(image) which takes an image as its argument and returns True if the image is valid and False otherwise. An image is valid if it satisfies all the following conditions:
• It is a list of lists of integers only (no other types are valid).
• All rows in the image are of the same length (the image is rectangular). • Allintegersiintheimagelieintherange0≤i≤255.
You can test if an object is a list or an integer using the type function like so:
   >>> type(1) == int
   True
   >>> type(True) == int
   False
   >>> type([1,2,3]) == list
   True
   >>> type(None) == list
   False
Below are some example applications of the valid_image function:
   >>> validate_image([]) # the empty image is valid
   True
   >>> validate_image([1]) # not a list of lists of integers
   False
   >>> validate_image(None) # not a list at all
   False
   >>> validate_image([[0,23,97,45], [125,3,12,1], [8,8,8,8]])
   True
   >>> validate_image([[1,2,3], [4,5]]) # rows different length
   False
   >>> validate_image([[1,2,3], [4,5,256]]) # 256 > maximum intensity
   False
2 回复
#2
pangding2012-08-30 01:49
没看明白问题和后面说的有什么关系……
#3
liuxufeng2012-09-01 19:02
和ls同样的问题

按照解释不就是那样吗
1