python 区分输入的数字是奇数还是偶数 10
defeven_only(l):"""PRE:lisalistofintegers.POST:lremainsunchangedANDthefunctionreturns...
def even_only(l):
"""
PRE: l is a list of integers.
POST: l remains unchanged AND the function returns a new list containing all (and only) the even elements of l.
"""
#- test harness: do not modify -#
l1 = [1, 3, 6, 10, 15, 21, 28]
l2 = [1, 4, 9, 16, 25]
ret1 = even_only(l1)
print ret1 # should be "[6, 10, 28]"
print l1 # should be "[1, 3, 6, 10, 15, 21, 28]"
ret2 = even_only(l2)
print ret2 # should be "[4, 16]"
print l2 # should be "[1, 4, 9, 16, 25]"
完善程序。。谢谢大侠。。。。 展开
"""
PRE: l is a list of integers.
POST: l remains unchanged AND the function returns a new list containing all (and only) the even elements of l.
"""
#- test harness: do not modify -#
l1 = [1, 3, 6, 10, 15, 21, 28]
l2 = [1, 4, 9, 16, 25]
ret1 = even_only(l1)
print ret1 # should be "[6, 10, 28]"
print l1 # should be "[1, 3, 6, 10, 15, 21, 28]"
ret2 = even_only(l2)
print ret2 # should be "[4, 16]"
print l2 # should be "[1, 4, 9, 16, 25]"
完善程序。。谢谢大侠。。。。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询