159k views
4 votes
USING ONLY SYS and MATH MODULES please

Your program must take command line arguments – an input filename and an output filename. 2. You can import the sys and math modules but no others. 3. Sample input data for your program is provided in the accompanying file (assignment1_input.txt) which is a plain text file. Where appropriate, fields are separated by tabs (eg for problem 1, two integers are provided separated by a tab character). Long strings are provided on a single line even if that line is wrapped over several lines ie there are no newline characters in the string. 4. You must implement a separate function within your program for each of the problems. 5. The functions must return the result of the computation and not write the result to file. 6. Your solution should be written as a module so it must have a main() function which contains the 'driver' code ie read input and write output, prepare data and call functions. This will also require conditional execution of main(). 7. The results of all problem solutions should be written to a single file (output_assignment1.txt). Each problem answer, which may of course be multiline, should be preceded by a line containing 2 hash (#) marks followed by the name of the problem. For example: ##INI2 Your answer
Your code should be a general solution so it should be able to handle any input file with this format – ie the inputs could be in any order so your code DOES NOT count lines to decide which function to call. Your code will be tested with another input file which maintains this format but with different, randomized inputs
Input.txt:
##INI2
997 949
##INI3
qQLXgmYrUBP3vOHWY8b9aumbUZFsXWKc1OkUERvQ9ncJAlK2T6uWr8BbH0PH9LimnodromusT8yxOGlFJ7qOZCWPJEVSmarcianuspO62TLrhPKzbxBY0QBctFbwrP7BQCMKPqGtQB3bEl9RSxaOF4XwKCic3dQ3dUtYzJBj7voTmBzVAm6pLnLML1x 61 71 92 100
##RNA
GTCCGAACCACTCCGTTTGTCAAGATTCATGGATCGGCGTCTCAATTTGGCTCCGGTTACAAGGCGCCAATCCAGTCCTCATAAAGTGTCTCCGCCACCCCGATGATACTTACTATACGACTCTAATTTGTGGTCGGTCAGACTCCCAAGTGAACTAACCCACGTTGCTGGGTCCAGGTTTGAGTGCCTACTTCACTACTTTAGCTCTTATGTGCCGATTGAGCCCATAATTCTGTCTGAATAAGTGGCTTAAGAGAGGGAGCCTTGGGAGGATCTAGGACTATCTTGCGCTTAATTGTTCGTACTACTTGGCACAGCGAGGTCGTGATTGATCAAGATCCGAATGTGATGGGCACCTAACAGGCGATGTTTCGCACTAACCGAGGCTCCAGGCAGACGGGCCTAGAGGTGGGGCGTCTTTTTATCATGTACACTCTGGCTGTAGACCTTGAATGCGGTGTCAAATGCCCGAGACGAACGCCGGGTCTTTCCATCCTCATAGCCATGGATCCACACATCGGCGGCCTTAATCTCTGACACGTCTCAAACAGAGTTTAAGTTTCGTACGCTTTGCTGTCCTAACCAAAGTACTAGTTCAGACAGTGCTCCACGTGATATGTTATGGACTCACCGCTGATGACATGCTAGTTCGTTCACAGGAGTGTAGCATCTATTGTCACTATTACGTGGCGGAGAGCGCGAGTCATCCTGATGTGAGGAGAGCGCCGACTAGAACCAGCAAGGTATAGCTGAAGTCGTCAAATCCGGCCAGCAAATGGGTTTTCTTACTGCGGGCAACTGGTTGCGCGGGGGCAACAGTTGCTGTCTATTCGTTATATTGATAAAGCCAATCAGACCAACCAAAATCGGGTAATAGACCACCAAAACGCAATTTTGGGGAAGTCACGTGAGTTTGCGGCGCAACATT

##DNA
ACCTATTGAGGAGAATTGTGTGTCGATGCTAAAGGCGTTCTCTCATCCCGCTATGTTCAAGACAGATCAGAATAAAAGGACCATACTCTGAGGACGATAGGATTAACATTGTATTCAATATGCAGGATGGTTCACAAATAATCTAGGTCCGACTTAGTGGCTGCTATGGAGTAACTTTACCACGTTGCGTATAGGTTAGTGCAGTAGCTTCGCCTTGGCCGTGCTCCTGTTCTGGTGCGTGAGAACGCCTTATGAAACCAAAGGTTAGCGGTTAACAGAGATGCCTGGTGGGTGCGTACCCTCCTCCGCCTCGATGCAATGGCCCCGCATCATCCACCAAAGCTATTACCCAGAAAACAGGTTGCTAACATGTAACAGAAGGGGCGGTTATGGTGTGCACTAGGTTTTACTCGGTCAGCGAAGAAGCCGCCGGTCAGGAGCTCCCGATAAGGCCCGCCACCAGTTGGAGACAAATTACCAAGAAGGTAGCTTAATTCCTCGAAGAGAATTGGTGCTTACAGGCATACATCAACCGGCGATTGAGTGGGAATATCACCACTAGCATTCCTCGACCTCGATCCGTGGAACCGCACGGTATCTTTTCGAACTCGTACCAGTCTGATTCCATGTAAGCGCGTATTCTGCATGCGGGCCGAAAATGCGGCCCTCCTACGGGTCAGCTGAGCTGAAGACTATCGTCACGAGTGTAGCCCGGTACGGATCACTGGCTACACTCGTCTTCGGCGGACGTCGAAGTCTCAAAGCACTAGAGTTTACCGATCTAGATCGCTTGAGCAGTGAAATGGGGGACCTAGCCAGAAAATATCTGCAAATCCGCAGTACCTAACGCGTCACATCCAG
##INI4
4984 9310
##INI2
756 834
##INI6
When I find myself in times of trouble Mother Mary comes to me Speaking words of wisdom let it be And in my hour of darkness she is standing right in front of me Speaking words of wisdom let it be Let it be let it be let it be let it be Whisper words of wisdom let it be And when the broken hearted people living in the world agree There will be an answer let it be For though they may be parted there is still a chance that they will see There will be an answer let it be Let it be let it be let it be let it be There will be an answer let it be Let it be let it be let it be let it be Whisper words of wisdom let it be Let it be let it be let it be let it be Whisper words of wisdom let it be And when the night is cloudy there is still a light that shines on me Shine until tomorrow let it be I wake up to the sound of music Mother Mary comes to me Speaking words of wisdom let it be Let it be let it be let it be yeah let it be There will be an answer let it be Let it be let it be let it be yeah let it be Whisper words of wisdom let it be
##INI4
360 4986
##INI6
The quick brown fox jumped over the lazy dog dog dog

User Jalone
by
8.5k points

1 Answer

5 votes

Final answer:

The question involves writing a Python module using only sys and math modules to process data from a text file, execute problem-specific functions, and write the output to another file. It requires an understanding of command-line argument handling, modularity, and conditional execution in Python programming, adhering to guidelines of input/output file structures.

Step-by-step explanation:

Leveraging sys and math modules in Python for educational purposes involves understanding command-line argument handling, file I/O operations, and performing mathematical computations. In a use case where only sys and math are permitted, students typically learn how to read input from a file, process the data according to specific problem requirements, and write the results to an output file. They must architect their code to include a main() function as the entry point, coupled with conditional execution ensuring the script only runs when executed as the main program.

The task could involve parsing input from a provided text file (assignment1_input.txt), where each function aligns with a distinct problem (e.g., 'INI2', 'DNA', 'RNA', etc.). Students demonstrate their understanding of creating modular code, defining problem-specific functions, and using math-based logic within these functions.

The output is then collated and written to another file (output_assignment1.txt) in a specified format, showcasing the ability to handle and adapt to different or randomized inputs that adhere to a predefined structure.

User Pyrospade
by
8.4k points