望采纳,谢谢!
def coding(s):
n = len(s)
#print(n)
if s.count("0" ) == n:
return 'A'
elif s.count('1') == n:
return 'B'
else:
return 'C' + ' '+ s[:n//2] + ' '+ s[n//2:]
s = input()
print(coding(s))
就先不说你的逻辑问题了,分割字符串可以这样 s[0:n//2] s[n//2:-1],比如n=4.那么就是0:2,2:-1
添加代码如下:
n = len(s)
temp = ""
temp1 = ""
for i in range(n/2):
temp += s[i]
for j in range(n/2):
temp1 += s[-j]
望采纳