鱼C论坛

 找回密码
 立即注册
查看: 13069|回复: 82

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

[复制链接]
发表于 2017-8-11 17:28:14 | 显示全部楼层
本帖最后由 chunchun2017 于 2017-8-12 10:20 编辑
  1. def NewBand(str):
  2.     str0=str.capitalize()
  3.     if(str[0]==str[-1]):
  4.         str0+=str[1:]
  5.     else:
  6.         str0='The '+str0
  7.     print(str0)
  8. name = input("Please input The band name:")
  9. NewBand(name)
复制代码


运行结果:
====================== RESTART: F:\Python3\code\名字问题.py ======================
Please input The band name:dolphin
The Dolphin
>>>
====================== RESTART: F:\Python3\code\名字问题.py ======================
Please input The band name:alaska
Alaskalaska
>>>
====================== RESTART: F:\Python3\code\名字问题.py ======================
Please input The band name:europe
Europeurope
>>>

上面的代码可以继续精简为:
  1. def NewBrandName(s):
  2.     print (s.capitalize()+s[1:] if s[0]==s[-1] else "The "+s.capitalize())
  3. s = input("请输入名字:")
  4. NewBrandName(s)
复制代码

评分

参与人数 1荣誉 +4 鱼币 +4 收起 理由
新手·ing + 4 + 4

查看全部评分

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-9-23 08:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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