python 练习题-字符串分割

题目:

https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7?tpId=37&tqId=21227&rp=1&ru=%2Fta%2Fhuawei&qru=%2Fta%2Fhuawei%2Fquestion-ranking&tab=answerKey

 1 # @Author  :whyCai
 2 # @Time    :2021/4/5 23:40
 3 
 4 '''
 5 题目描述
 6 •连续输入字符串,请按长度为8拆分每个字符串后输出到新的字符串数组;
 7 •长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。
 8 
 9 输入描述:
10 连续输入字符串(输入多次,每个字符串长度小于100)
11 
12 输出描述:
13 输出到长度为8的新字符串数组
14 
15 示例1
16 输入
17 abc
18 123456789
19 输出
20 abc00000
21 12345678
22 90000000
23 '''
24 
25 
26 while True:
27     try:
28         s = input()
29         #长度为0时,报错退出
30         a = 1/len(s)
31         while len(s)>8:
32             print(s[:8])
33             s = s[8:]
34         print(s + (8 - len(s)) * '0')
35     except:
36         break
原文地址:https://www.cnblogs.com/whycai/p/14623686.html