标题:新手求助一个关于define function的问题
只看楼主
GodBlessMe
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-8-27
结帖率:0
已结贴  问题点数:20 回复次数:2 
新手求助一个关于define function的问题
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
搜索更多相关主题的帖子: only following otherwise function 
2012-08-27 13:39
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
得分:10 
没看明白问题和后面说的有什么关系……
2012-08-30 01:49
liuxufeng
Rank: 2
等 级:论坛游民
帖 子:10
专家分:10
注 册:2012-7-30
得分:10 
和ls同样的问题

按照解释不就是那样吗
2012-09-01 19:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-380174-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.340124 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved