Write a program in python that reads a input file (that consists of many data chunks,…
- User
Write a program in python that reads a input file (that consists of many data chunks, which are divided amongst each other via two line breaks) and does the following:
The program has some constants: line_2 = "2" line_6, line_7 = ""
At the begin it shall look for the sequence 'X ' within the data chunk. If it finds it, it shall read the text right beside it until ')' is reached. If the text is equal to ' a', then the output is '1 0 0'. If the text is equal to ' b', then the output is '0 1 0' If the text is equal to ' c', then the output is '0 0 1'. It saves the output into a string called 'line_8'.
Firstly it shall look for a pattern consisting of four numbers separated by a space and ending with a space. It shall save this text without the last space in a string called 'line_1'.
Secondly it shall look for a pattern consisting of four numbers separated by space and ending with a space. Everything beginning after this sequence until it reaches a line break followed by either 'a)' OR 'X a)' shall be saved in the string called 'line_0'. 'line_0' is then checked for any line breaks within, which shall be replaced by a space.
Thirdly it shall look for the sequence 'a) '. Everything beginning after this sequence until it reaches a line break followed by either 'b)' OR 'X b)' shall be saved in the string called 'line_3'. 'line_3' is then checked for any line breaks within, which shall be replaced by a space.
Fourthly it shall look for the sequence 'b) '. Everything beginning after this sequence until it reaches a line break followed by either 'c)' OR 'X c)' shall be saved in the string called 'line_4'. 'line_4' is then checked for any line breaks within, which shall be replaced by a space.
Fifthly it shall look for the sequence 'c) '. Everything beginning after this sequence until the end of the data chunk shall be saved in the string called 'line_5'. 'line_5' is then checked for any line breaks within, which shall be replaced by a space.
Lastly, the program combines these strings as follow in a new string called 'result': result = "'line_0'"\t"'line_1'"\t"line_2"\t"'line_3'"\t"'line_4'"\t"'line_5'"\t"'line_6'"\t"'line_7'"\t"'line_8'"\t\n" 'result' is now written in the output file.
Then the program moves to the next data chunk.
- Assistant