Codewars note: I love you, a little , a lot, passionately ... not at al

My Codewars

DESCRIPTION:

Who remembers back to their time in the schoolyard, when girls would take a flower and tear its petals, saying each of the following phrases each time a petal was torn:

  • I love you
  • a little
  • a lot
  • passionately
  • madly
  • not at all

When the last petal was torn there were cries of excitement, dreams, surging thoughts and emotions.

Your goal in this kata is to determine which phrase the girls would say for a flower of a given number of petals, where nb_petals > 0.

 

Solution:

1

def how_much_i_love_you(nb_petals):
    dict = {1:'I love you',2:'a little',3:'a lot',4:'passionately',5:'madly',0:'not at all'}
    return dict[nb_petals % 6]

2

def how_much_i_love_you(nb_petals):
    return ["not at all", "I love you", "a little", "a lot", "passionately", "madly"][nb_petals % 6]

 

posted @   大序列  阅读(187)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示