Python入门实战:Round 4
哈,这个系列是跟小肉镊菹告伙伴一起组织的Python兴趣小组的习题,每一期内容会包括三个部分:题目、小伙伴答案和全球开发者答案。话不多说,Show you the code ~
工具/原料
题目来源:Codewars
Python 2.7
Round 4# RGB To Hex Conversion
1、The rgb() method is incomplete. Complete the method so that passing in RGB decimal values will result in a hexadecimal representation being returned. The valid decimal values for RGB are 0 - 255. Any (r,g,b) argument values that fall out of that range should be rounded to the closest valid value.The following are examples of expected output values:
2、上次练习是2进制,这次是16进制
Local answers
1、这次的答案里,有一部分是需要大家阅读代码以后要去避免的
2、这里一个比较显著的问题还是pythonic,要写Python风格的代码
3、代码行数的差异也很有趣 :P
4、最后两个答案写了辅助函数,这个是真的要点赞!
Global answers
1、全球开发者的答案用了匿名函数,但是可读性变差了,感觉不好
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。