Question
[Python] Functionality You are to create a program that properly handles two types of input-- command line arguments and standard input. The purpose of this
[Python]
Functionality
You are to create a program that properly handles two types of input-- command line arguments and standard input. The purpose of this exercise is to ensure that you can effectively handle both types of input and that you clearly understand the differences. In particular, the program will perform as follows:
There are three possible command line arguments for this program: option1, option2, and option3. Each option appears following a single dash ('-'). A word of text follows certain options. Your program must read the actual arguments present and store any additional data associated with them.
The options appear on the command line as follows:
option1: -o
option2: -t
option3: -h
A word always follows option1 and option2. There is no data following option3.
Any, all, or none of these options may be present on the command line; moreover, they may be present in any order. Your program must properly handle all possible combinations. For example, option3 (-h) may be present, followed by option1 (-o), while option2 is not present on the command line.
In addition to command line arguments, your program must also read data from standard input.
Your program will read data from standard input one line at a time. Your program must continue reading until there is no more data from standard input.
When your program starts, it must output the heading, "Standard Input:" (without quotation marks).
As your program reads a line from standard input, it will output the line immediately to standard output.
Once all data has been read from standard input and output accordingly, your program will output the heading, "Command line arguments:" (again, without quotation marks); your program will then display a list of the command line options found, along with their data, in numeric order. In other words, option1 must be displayed first, if present, then option2, and finally option3. The heading must be output even if there are no command line arguments. DO NOT DISPLAY AN OPTION IF IT IS NOT PRESENT ON THE COMMAND LINE.
If you write your program using Python, you can use the getopt.getopt function, which will do much of the heavy lifting for you.
Example 1: Execution on Windows (< Windows 10)
Command line:
Python:
py input_program.py -h -t giraffe
Standard input entered: zebra, hyena, CTRL-z
Output as it should appear:
Standard Input:
zebra
zebra
hyena
hyena
^Z
Command line arguments:
option 2: giraffe
option 3
Example 2: Execution on Linux, Mac, or Windows 10 (depending on configuration)
Command line:
Python:
py input_program.py -t lion -h -o elephant
Standard input entered: hippopotamus, CTRL-d
Output:
Standard Input:
hippopotamus
hippopotamus
Command line arguments:
option 1: elephant
option 2: lion
option 3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started