Check if all digits of the given integer are even.
Example
- For
n = 248622
, the output should beevenDigitsOnly(n) = true
; - For
n = 642386
, the output should beevenDigitsOnly(n) = false
.
我的解答:
def evenDigitsOnly(n): for i in range(len(str(n))): if int(str(n)[i]) % 2 != 0: return False return True
def evenDigitsOnly(n): return all([int(i)%2==0 for i in str(n)]) 想起来用列表推导式了...但没想起来all函数....