Check if all digits of the given integer are even.

Example

    • For n = 248622, the output should be
      evenDigitsOnly(n) = true;
    • For n = 642386, the output should be
      evenDigitsOnly(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函数....

膜拜大佬

Code Signal_练习题_evenDigitsOnly的更多相关文章

  1. Code Signal_练习题_digitDegree

    Let's define digit degree of some positive integer as the number of times we need to replace this nu ...

  2. Code Signal_练习题_Knapsack Light

    You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...

  3. Code Signal_练习题_growingPlant

    Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...

  4. Code Signal_练习题_arrayMaxConsecutiveSum

    Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...

  5. Code Signal_练习题_differentSymbolsNaive

    Given a string, find the number of different characters in it. Example For s = "cabca", th ...

  6. Code Signal_练习题_firstDigit

    Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...

  7. Code Signal_练习题_extractEachKth

    Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...

  8. Code Signal_练习题_stringsRearrangement

    Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...

  9. Code Signal_练习题_absoluteValuesSumMinimization

    Given a sorted array of integers a, find an integer x from a such that the value of abs(a[0] - x) + ...

随机推荐

  1. wcf返回值报错解析

    问题来源 最近在项目中使用wcf,因为是一个新手,对新的东西总是比较敬畏,不过一切都是进行得很顺利,运行的时候,突然报了错,编译器提示的错误大概是:“InvalidOperationException ...

  2. java爬虫学习

    一.java爬取数据 示例:爬取网站中的所有古风网名:http://www.oicq88.com/gufeng/,并储存入数据库(mysql) jdk版本:jdk1.8 编辑器:idea 项目构建:m ...

  3. 机器学习与Tensorflow(1)——机器学习基本概念、tensorflow实现简单线性回归

    一.机器学习基本概念 1.训练集和测试集 训练集(training set/data)/训练样例(training examples): 用来进行训练,也就是产生模型或者算法的数据集 测试集(test ...

  4. Flask-socketio聊天室 (附源码)

    `* A Chat Room Completed with Flask-socketio 功能: 实时消息更新,实时用户上线显示 快捷注册 快捷登陆 表情支持 截图: 使用方法: 安装依赖:pip i ...

  5. Grape简介

    什么是Grape Grape是Ruby中的一个类REST API框架,被设计用于运行在Rack上或弥补已有的web应用框架(比如Rails或者Sinatra),Grape提供了一个简单的DSL用于方便 ...

  6. Javac中的nullcheck

    Javac会通过调用引用对象的getClass()来判空,主要有几处: (1)JCMethodInvocation()方法中,如下实例: class A{ class B{} } public cla ...

  7. nginx配置文件nginx.conf 不包括server节点

    整理的一个nginx.conf的配置,不包括server节点介绍 原文请查看,Nginx配置文件(nginx.conf)配置详解 # For more information on configura ...

  8. JDK8简化if-else

    简化if-else 1234567891011 User user = ...if (user != null) { String userName = user.getUserName(); if ...

  9. a no-risk path to IEEE P1687

    You’ve heard all about IJTAG (IEEE P1687) [1,2,3], a new standard for accessing embedded test and 
d ...

  10. 利用latex制作个人简历

    转自: http://www.cnblogs.com/panpei/ 前些日子,有点无聊,就在网上逛逛技术大牛的blogs,发现很多大牛都喜欢用pdf版式的简历,发现这种版式的简历排版非常漂亮简洁.深 ...