亦或操作判断中间是否要加入*
以上,供参考
while True: try: s = input() res = [] # for i in s: # if i.isdigit(): # res.extend(['*', i, '*']) # else: # res.append(i) # print(''.join(res).replace('**', '')) # 测试数据中会有 * 出现,所以不能这样处理 s1 = 'a'+s s2 = s+'a' for i, j in zip(s1, s2): if i.isdigit() ^ j.isdigit(): res.append('*') res.append(j) print(''.join(res[:-1])) except: break