|
发表于 2017-8-11 17:28:14
|
显示全部楼层
本帖最后由 chunchun2017 于 2017-8-12 10:20 编辑
- def NewBand(str):
- str0=str.capitalize()
- if(str[0]==str[-1]):
- str0+=str[1:]
- else:
- str0='The '+str0
- print(str0)
- name = input("Please input The band name:")
- 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
>>>
上面的代码可以继续精简为:
- def NewBrandName(s):
- print (s.capitalize()+s[1:] if s[0]==s[-1] else "The "+s.capitalize())
- s = input("请输入名字:")
- NewBrandName(s)
复制代码 |
评分
-
查看全部评分
|