Python入门实战:Round 4

 时间:2024-10-31 11:09:15

哈,这个系列是跟小肉镊菹告伙伴一起组织的Python兴趣小组的习题,每一期内容会包括三个部分:题目、小伙伴答案和全球开发者答案。话不多说,Show you the code ~

Python入门实战:Round 4

工具/原料

题目来源: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:

Python入门实战:Round 4

2、上次练习是2进制,这次是16进制

Python入门实战:Round 4

Local answers

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

Python入门实战:Round 4

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

Python入门实战:Round 4

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

Python入门实战:Round 4

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

Python入门实战:Round 4

Global answers

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

Python入门实战:Round 4
  • 狗不能吃什么食物
  • 简单做法的糖醋藕
  • IKEA宜家家居怎么查看软件版本号
  • 怎样拍摄生态微距
  • 火柴人部落雇佣军团怎么玩?
  • 热门搜索
    巴宝莉手表怎么样 如何让头发长得快 刷机精灵怎么用 腾达路由器怎么样 长安cx20怎么样 色戒哪里可以看 如何买二手车 珠穆朗玛峰旅游 旅游的说说心情朋友圈 台山旅游