Python等级考试五级编程题:写出字符串str的p型编码串。
给定一个完全由数字字符('0','1','2',...,'9')构成的字符串str,请写出str的p型编码串,规则如下:
1335554668对应描述为「1个1、2个3、3个5、1个4、2个6、1个8」,编码结果为11233514261800000000000(共11个0),编码结果为110110003444225对应描述为「2个1、3个0、1个3、3个4、2个2、1个5」,编码结果为213013342215s = input("请输入字符串str:")
s += ' '
lens = len(s)
for i in range(0, ① , 1):
if '0' <= s[i] <= '9':
②
else:
print('输入无效!')
exit()
sum = 1
i = 0
while i < lens - 1:
if ③ :
sum += 1
else:
print(sum, end='')
print(s[i], end='')
④
i += 1