大家可以看看这个缩写判断该如何处理吗 | python | python 技术论坛-江南app体育官方入口

#*coding:utf-8__*__

n_num=int(input())
result=[]
ss=””
while n_num:
n_num-=1
wen=input().split()
for i in range(len(wen)):
ss =wen[i][0]
ss.upper()
result.append(ss)
if result[0]==result[-1]:
print(“same”)
else:
print(“different”)

讨论数量: 1
jason990420

example code

n = int(input("how many test cases ?"))
i = 0
while i < n:
    s1 = input(f"1st name for test {i1}")
    ss1 = "".join([word[0] for word in s1.split()]).upper()
    s2 = input(f"2nd name for test {i1}")
    ss2 = "".join([word[0] for word in s2.split()]).upper()
    if ss1 == ss2:
        print(f"same: {ss1}")
    else:
        print("different: {ss1} vs {ss2}")
how many test cases ?3
1st name for test 1:advanced breast cancer
2nd name for test 1:active body control
same: abc
1st name for test 2:cell division cycle
2nd name for test 2:control data corporation
same: cdc
1st name for test 3:national auto sport association
2nd name for test 3:north america and south america
different: nasa vs naasa
done !

or, you can do it by

import re
def acronym(string):
   words = re.findall(r'\b\w', string.upper())
   return "".join(words)
1个月前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
网站地图