第二次作业

这个作业属于哪个课程 https://edu.cnblogs.com/campus/zjlg/rjjc
这个作业的目标 实现一个命令行文本计数统计程序,能正确统计导入的txt文本中的字符数、单词数、句子数、代码行、空行、注释行等
姓名-学号 肖健飞-2022329301124

作业码云地址:https://gitee.com/xazurx/rjjc

介绍

这是一个能够实现命令行文本计数统计的Python程序项目。

基础功能:能正确统计导入的纯英文txt文本中的字符数,单词数,句子数。
扩展功能:能正确统计导入的纯英文txt文本中的代码行、空行、注释行等,并提供相应命令接口。

基础功能

  1. 统计纯英文文本中的字符数、单词数和句子数。
  2. 对测试数据进行测试。

拓展功能

  1. 统计纯英文文本中的代码行、空行、注释行数。
  2. 对测试数据进行测试。

使用方法说明

基础功能指令表

python test.py -c file.txt # 统计字符数
python test.py -w file.txt # 统计单词数
python test.py -s file.txt # 统计句子数

拓展功能指令表

python wc.py -l file.txt # 统计代码行数
python wc.py -e file.txt # 统计空行数
python wc.py -m file.txt # 统计注释行数 

功能展示

基础功能展示

  • 作为测试用的text.txt文本展示如下
He was an old man who fished alone in a skiff in the Gulf Stream and he had gone eighty-four days now without taking a fish. In the first forty days a boy had been with him. But after forty days without a fish the boy's parents had told him that the old man was now definitely and finally salao, which is the worst form of unlucky, and the boy had gone at their orders in another boat which caught three good fish the first week. 

It made the boy sad to see the old man come in each day with his skiff empty and he always went down to help him carry either the coiled lines or the gaff and harpoon and the sail that was furled around the mast. The sail was patched with flour sacks and, furled, it looked like the flag of permanent defeat. 

The old man was thin and gaunt with deep wrinkles in the back of his neck. The brown blotches of the benevolent skin cancer the sun brings from its reflection on the tropic sea were on his cheeks.

The blotches ran well down the sides of his face and his hands had the deep-creased scars from handling heavy fish on the cords. But none of these scars were fresh. They were as old as erosions in a fishless desert. 

Everything about him was old except his eyes and they were the same color as the sea and were cheerful and undefeated. 

"Santiago," the boy said to him as they climbed the bank from where the skiff was hauled up. "I could go with you again. We've made some money." 

The old man had taught the boy to fish and the boy loved him.

"No," the old man said. "You're with a lucky boat. Stay with them." 

"But remember how you went eighty-seven days without fish and then we caught big ones every day for three weeks." 

"I remember," the old man said. "I know you did not leave me because you doubted." 

"It was papa made me leave. I am a boy and I must obey him." 

"I know," the old man said. "It is quite normal." "He hasn't much faith." "No," the old man said. "But we have. Haven't we?" "Yes," the boy said. "Can I offer you a beer on the Terrace and then we'll take the stuff home."

"Why not?" the old man said, "Between fishermen." 

They sat on the Terrace and many of the fishermen made fun of the old man and he was not angry. Others, of the older fishermen, looked at him and were sad. But they did not show it and they spoke politely about the current and the depths they had drifted their lines at and the steady good weather and of what they had seen.
  • Input
python test.py -c text.txt 
python test.py -w text.txt
python test.py -s text.txt
  • Output
字符数: 2423
单词数: 481
句子数: 36

拓展功能展示

  • Input
python wc.py -l file.txt
python wc.py -e file.txt
python wc.py -m file.txt
  • Output
总行数: 27
空行数: 13
注释行数: 0

posted @ 2024-10-28 23:01    阅读(10)  评论(0编辑  收藏  举报