题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
a = input() n = len(a) i = 0 while i * 8 < n: if i * 8 + 8 > n: b = 8 - n % 8 e = [] for j in a[i * 8:]: e.append(j) e.extend(['0'] * b) print(''.join(e)) break print(''.join(a[i * 8: i * 8 + 8])) i += 1
while i * 8 < n: 和 if i * 8 + 8 > n:注意边界值处理,否则容易出现多出的行