求好心人帮助! python问题 首字母缩写
Acronyms(首字母缩写词)Writeaprogram(inafilecalledacronyms.py)thatasksauserforaphraseandprin...
Acronyms
(首字母缩写词)
Write a program (in a file called acronyms.py) that asks a user for a phrase and prints the acronym of that phrase. You program should ignore the words the, of, and at. Here are some examples:
(写一个程序(一个名为acronyms.py),要求用户一个短语,并打印出这句话的缩写。你的程序应该忽略的话,,和。下面是一些例子:)
input output
University of British Columbia UBC
Alexander College AC
Simon Fraser University SFU
Massachusetts Institute of Technology MIT
See you later syl
Be right back brb
Talk to you later ttyl 展开
(首字母缩写词)
Write a program (in a file called acronyms.py) that asks a user for a phrase and prints the acronym of that phrase. You program should ignore the words the, of, and at. Here are some examples:
(写一个程序(一个名为acronyms.py),要求用户一个短语,并打印出这句话的缩写。你的程序应该忽略的话,,和。下面是一些例子:)
input output
University of British Columbia UBC
Alexander College AC
Simon Fraser University SFU
Massachusetts Institute of Technology MIT
See you later syl
Be right back brb
Talk to you later ttyl 展开
3个回答
展开全部
你好!你问了同样的问题,以下是我的程序:
phrase = raw_input("Enter a phrase: ")
words = phrase.split(" ")
letters = []
for i in words:
if i == "the" or i == "at" or i == "of":
words.remove(i)
for i in words:
letters.append(i[0])
print "".join(letters)
希望可以帮到你,如果不懂可追问,还有其他要求也可以提问,望采纳!
phrase = raw_input("Enter a phrase: ")
words = phrase.split(" ")
letters = []
for i in words:
if i == "the" or i == "at" or i == "of":
words.remove(i)
for i in words:
letters.append(i[0])
print "".join(letters)
希望可以帮到你,如果不懂可追问,还有其他要求也可以提问,望采纳!
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
给你举个例子吧:
base_str = "University of British Columbia"
ignore_str = ["the", "of", "at"]
answer = ""
for s in base_str.split():
if s in ignore_str:
continue
answer += s[0]
print answer
注意,我这边大小写都没处理,这个你自己想想吧
base_str = "University of British Columbia"
ignore_str = ["the", "of", "at"]
answer = ""
for s in base_str.split():
if s in ignore_str:
continue
answer += s[0]
print answer
注意,我这边大小写都没处理,这个你自己想想吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询