鱼C论坛

 找回密码
 立即注册
查看: 12530|回复: 92

[技术交流] Python:每日一题 78(答题领鱼币)

[复制链接]
发表于 2019-9-28 22:04:38 | 显示全部楼层
def average_string(string:str):
    dict_num ={'one':1,'two':2,'three':3,'four':4,'five':5,'six':6,'seven':7}
    total =[]
    temp = string.split(' ')
    count = 0
    for each in temp:
        if each not in dict_num:
            return 'n/a'
        else:
            total.append(dict_num[each])
            count+=1
    a = sum(total)//count
   
    return ''.join([k for (k,v) in dict_num.items() if v == a])
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-16 02:51

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表