python求总数_python 求file 里各列variable的总数和各个分类的总数!

#colorsizefleshclassbrownlargehardsafegreenlargehardsaferedlargesoftdangerousgreenlargesoftsaferedsmallhardsaferedsmallhardsafebrownsmallhardsafegreensmallsoftdangerousgr...

#color size flesh class

brown large hard safe

green large hard safe

red large soft dangerous

green large soft safe

red small hard safe

red small hard safe

brown small hard safe

green small soft dangerous

green small hard dangerous

red large hard safe

brown large soft safe

green small soft dangerous

red small soft safe

red large hard dangerous

red small hard safe

green small hard dangerous

file的txt文件是这样的(animals.txt)

要求算

Total number of animals?

Total number of dangerous animals?

Number of large animals that are safe?

Number of animals that are brown and dangerous?

Number of safe animals with red color or hard flesh?

前面open和check if exists 的都做好了 这里不会做了

还有要忽略file中的#和之后一行的注释也不会

求高手帮忙谢谢!

这是完整的问题:

Q Download the dataset animals.txt, which contains features of animals. The features : color,size,flesh and class are separated by spaces. Write a Python program that asks the user for the names of the input file (in this case animals.txt) and the output file (any name). The program reads in the lines of the input file, ignores comment lines (lines starting with #) and blank lines and computes and prints the answers to the following questions:

Total number of animals?

Total number of dangerous animals?

Number of large animals that are safe?

Number of animals that are brown and dangerous?

Number of safe animals with red color or hard flesh?

要求的display格式要是

Total animals =

Dangerous =

Brown and dangerous =

Large and safe =

Safe with red color or hard flesh =

还有第二个问题

Q2 Write a Python program that prompts the user to enter names of input file and output file,reads in all lines of the input file and then writes the lines in reverse order into the output file.For example, if the input file is frost.txt then the new file should look like newfrost.txt.

就是要把output的txt的名字变一下,比如说frost.txt 变成newfrost.txt 然后里面内容要从

The woods are lovely, dark and deep.

But I have promises to keep,

And miles to go before I sleep,

And miles to go before I sleep.

变成

And miles to go before I sleep.

And miles to go before I sleep,

But I have promises to keep,

The woods are lovely, dark and deep.

就是都倒过来

求解!

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值