首页 > 编程语言 > 详细

Codewar python训练题全记录——持续更新

时间:2017-04-09 09:49:31      阅读:466      评论:0      收藏:0      [点我收藏+]

1.square 数的判断

from math import sqrt
def is_quare(n): return n > 0 and sqrt(n).is_integer()

point:

from math import sqrt

is_integer()命令使用

% 求余符号的使用

return () 可以直接返回 T or F

2. two fighters and one winners

技术分享

 

point:

ceil() 取上整数命令, 【考虑到实际情况中 damage 值多为Integer, 所以用ceil()取整】

技术分享

attrgetter() 定位命令??  【attribute 可以自己创建, 例如本例子中的 turn attribute】

技术分享

 

技术分享

技术分享

 

 3. find needle in the haystack 

point: 

index() method 使用, 占位符的应用  

return 代替 print

enumerate() method 使用 

str.format() 字符的占位符? 可以应用公式的占位符??

技术分享

技术分享

技术分享

 

技术分享

技术分享

 

Codewar python训练题全记录——持续更新

原文:http://www.cnblogs.com/kong-xy/p/6683545.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!