zoukankan      html  css  js  c++  java
  • 第6章函数-6 缩写词

    缩写词是由一个短语中每个单词的第一个字母组成,均为大写。例如,CPU是短语“central processing unit”的缩写。

    函数接口定义:

    acronym(phrase);
    phrase是短语参数,返回短语的缩写词
    
    
    

    裁判测试程序样例:

    
    /* 请在这里填写答案 */
    
    
    

    phrase=input()
    print(acronym(phrase))

    输入样例:

    central  processing  unit
    
    
    

    输出样例:

    CPU

    代码如下:

    def acronym(s):
        s1 = s.title()
        list1 = list()
        for i in range(0,len(s)):
            if i == len(s)-2:
                break
            if ord(s1[i]) <= 90 and ord(s1[i]) >= 65:
                list1.append(s1[i])
                #蒽?
        return "".join(list1)

    这个程序不难,记住英文字母的大小写转换函数即可。

    # print(str.upper())          # 把所有字符中的小写字母转换成大写字母
    # print(str.lower())          # 把所有字符中的大写字母转换成小写字母
    # print(str.capitalize())     # 把第一个字母转化为大写字母,其余小写
    # print(str.title())          # 把每个单词的第一个字母转化为大写,其余小写
    # A-Z:65-90


    读书和健身总有一个在路上

  • 相关阅读:
    redis改配置
    redis主从复制
    nginx做维护页面
    go_http
    DRF源码-views.py
    DRF教程10-关系字段
    语言特性
    DRF源码-fields.py
    python_@classmethod
    HTML5:定位
  • 原文地址:https://www.cnblogs.com/Renqy/p/12777680.html
Copyright © 2011-2022 走看看