鱼C论坛

 找回密码
 立即注册
查看: 1542|回复: 2

[已解决]问题求助

[复制链接]
发表于 2020-9-15 18:58:36 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
给了一个单词 A,给了起始index,给了输出的单词长度,求输出的单词
最佳答案
2020-9-15 20:57:31
这样好像可以了


  1. def Check(a,b,index,length):
  2.     index=index+1
  3.     while length>0:
  4.         if b-index>length:
  5.             a=a
  6.         else:
  7.             a=a+a[::-1][1:]
  8.         length = length -(b-index)
  9.         index=0
  10.     return a


  11. a = 'quokkas'
  12. index = 3
  13. length = 6
  14. a=Check(a,len(a),index,length)
  15. print(a[index:index+length])

  16. b = 'jimbo'
  17. index = 4
  18. length = 9
  19. b=Check(b,len(b),index,length)
  20. print(b[index:index+length])

  21. c = 'apple'
  22. index = 0
  23. length = 9
  24. c=Check(c,len(c),index,length)
  25. print(c[index:index+length])


复制代码
屏幕快照 2020-09-15 下午8.55.40.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-9-15 20:57:31 | 显示全部楼层    本楼为最佳答案   
这样好像可以了


  1. def Check(a,b,index,length):
  2.     index=index+1
  3.     while length>0:
  4.         if b-index>length:
  5.             a=a
  6.         else:
  7.             a=a+a[::-1][1:]
  8.         length = length -(b-index)
  9.         index=0
  10.     return a


  11. a = 'quokkas'
  12. index = 3
  13. length = 6
  14. a=Check(a,len(a),index,length)
  15. print(a[index:index+length])

  16. b = 'jimbo'
  17. index = 4
  18. length = 9
  19. b=Check(b,len(b),index,length)
  20. print(b[index:index+length])

  21. c = 'apple'
  22. index = 0
  23. length = 9
  24. c=Check(c,len(c),index,length)
  25. print(c[index:index+length])


复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-9-15 20:58:54 | 显示全部楼层
还是上次的要求的话,自己用sys.argv改造下吧,主体程序就是这样了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-27 06:50

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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