多语言展示
当前在线:1041今日阅读:75今日分享:44

Python入门实战:Round 4

哈,这个系列是跟小伙伴一起组织的Python兴趣小组的习题,每一期内容会包括三个部分:题目、小伙伴答案和全球开发者答案。话不多说,Show you the code ~0Python入门实战:Round 30Python入门实战:Round 20Python入门实战:Round 1
工具/原料
1

题目来源:Codewars

2

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进盲雁爷制END

Local answers
1

这次的答案里,有一部分是需要大家阅读代码以后要去避免的

2

这里一个比较显著的问题还是pythonic,要写Python风格的代码

3

代码行数的差异也很有趣 :P

4

最后两个答案写了辅助函数,这个是真的要点赞!END

Global answers

全球开发者的答案用了匿名函数,但是可读性变差了,感觉不好END

注意事项

代码下载:https://pan.baidu.com/s/1qZOzLNm

推荐信息