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宜家家居怎么查看软件版本号
  • 怎样拍摄生态微距
  • 火柴人部落雇佣军团怎么玩?
  • 热门搜索
    上海最好吃的蛋糕 好词好句摘抄大全 肚子怎么减肥 螃蟹怎么做好吃又简单 股票怎么看成交量 快速瘦腿的方法 坐便堵了怎么办 糯米粉可以做什么好吃的简单方便 炒猪肝的家常做法 苦菊怎么凉拌好吃