python:通过while循环键盘录入字符串存入列表?

2025-04-13 01:16:26
推荐回答(1个)
回答(1):

L=[]
while True:
n=input('请录入字符')
L.append(n)
if n=='OK':
    lens=0
    for i in L:
        if len(i)>5:
            lens=lens+1
            with open('work.txt','a') as f:
                f.write(i)
if lens==0:
print('没有符合条件的元素,work.txt文件内容为空!')
break