鱼C论坛

 找回密码
 立即注册
12
返回列表 发新帖
楼主: 新手·ing

[已解决]Python:每日一题 154(高额悬赏)

[复制链接]
发表于 2018-2-18 17:55:08 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-2-20 08:26:28 | 显示全部楼层
6
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-2-21 11:07:06 | 显示全部楼层
  1. def high(x):
  2.     list_x = x.split(' ')
  3.     list_score = [sum([ord(j)-96 for j in i if j.isalpha()]) for i in list_x]
  4.     return list_x[list_score.index(max(list_score))]
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-3-4 21:53:31 | 显示全部楼层
  1. def score(string):
  2.     list_temp = list(string)
  3.     total = 0
  4.     for i in list_temp:
  5.         total += ord(i) - ord('a') + 1
  6.     return total


  7. def main():
  8.     word = input('请输入一个单词:')
  9.     sum = score(word)
  10.     print(sum)

  11. if __name__ == "__main__":
  12.     main()
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-3-8 23:12:22 | 显示全部楼层

如果要求既要返回这个单词,又要返回其分数值,请问该怎么修改呢?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-3-9 17:28:46 | 显示全部楼层
  1. def high(goal_str):
  2.     l1 = goal_str.split(' ')
  3.     tmp = []
  4.     for j in range(len(l1)):
  5.         tmp.append(sum([ord(i) - 96 for i in l1[j]]))

  6.     return l1[tmp.index(max(tmp))]

  7. str1 = input("please input a string:")
  8. print(high(str1))
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-5-26 21:56:37 | 显示全部楼层
分數高是什麼意思看不懂
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-5-28 21:24:14 | 显示全部楼层
ok
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-6-16 14:16:53 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2019-1-14 14:18:55 | 显示全部楼层
  1. def high(str):
  2.         dic = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7,
  3.                'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14,
  4.                'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20,
  5.                'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
  6.         list1 = str.split(' ')
  7.         list2 = []
  8.         for i in list1:
  9.                 temp = 0
  10.                 for j in i:
  11.                         temp += dic[j.lower()]
  12.                 list2.append(temp)
  13.         print('得分最高的单词是:%s\n在输入的字符串中是第 %d 个字符' % (list1[list2.index(max(list2))], list2.index(max(list2)) + 1))


  14. high('This is the wonderful world in my dream')
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2019-5-5 11:31:43 | 显示全部楼层
  1. def fun154(str1):
  2.     word_list = str1.split(" ")
  3.     word_sum = list(map(lambda x:sum([ord(i)-96 for i in x]),word_list))
  4.     index = word_sum.index(max(word_sum))
  5.     return word_list[index]
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-3-29 16:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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