14、Python 文件处理与递归算法实践

Python 文件处理与递归算法实践

1. 文件处理练习

1.1 一致行长度格式化

在终端窗口中显示文本时,由于窗口宽度不同,文本行可能过长而换行,导致阅读困难,或者过短而无法充分利用空间。为了解决这个问题,需要编写一个程序,将文件内容进行格式化,使每行尽可能填满。

示例文件内容如下:

Alice was
beginning to get very tired of sitting by her
sister
on the bank, and of having nothing to do: once
or twice she had peeped into the book her sister
was reading, but it had
no
pictures or conversations in it,"and what is
the use of a book," thought Alice, "without
pictures or conversations?"

格式化后,行长度为 50 字符的输出如下:

Alice was beginning to get very tired of sitting
by her sister on the bank, and of having nothing
to do: once or twice she had peeped into the book
her sister was reading, bu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值