大家可以看看这个缩写判断该如何处理吗

#*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 {i+1}")
    ss1 = "".join([word[0] for word in s1.split()]).upper()
    s2 = input(f"2nd name for Test {i+1}")
    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)
3个月前 评论

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