#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.
就是都倒过来
求解!
展开