Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment, you will write a Python program which reads a text file that associates languages with their ISO codes and character sets,
In this assignment, you will write a Python program which reads a text file that associates languages with their ISO codes and character sets, and outputs the requested information. (Just in case you are curious, a list of ISO codes can be found here: https://en.wikipedia.org/wiki/List_of_ISO 639- 1_codes, and a list of sets can be found here: https://en.wikipedia.org/wiki/Character_encoding, but they are not required for the assignment). These are the specifications for your Python program: It must be named languages.py It should be invoked as: python languages.py option argument_file In the command line above, option means one of the options described below, and argument_file means the chosen argument file, which can have any arbitrary name. 1. 2. The program must check that argument argument_file exists, is a file and is readable. If not, it must print an error message to the standard output and exit. The specifications for the argument_file and option arguments are given below. 3. File argument_file can have any arbitrary name. It must be a file of text with the following format: a. The file consists of an arbitrary number of lines (including, possibly, zero lines). b. Each line must contain three fields separated by one or more space characters. c. The three fields are: name, code, set. d. The name field is a string of characters representing the name of a language. e. The code field is a string of two characters representing the ISO code for the language. f. The set field is a string of characters representing the character set for the language. Fundamental note: your program is not expected to verify that file argument_file complies with the above specifications. It will only be tested with compliant files. The following example should be regarded as the reference specification for the format of file argument_file: German de ISO-8859-1 English en ISO-8859-1 Chinese zh GB2312 4. English en ISO-885 Chinese zh GB2312 Italian it ISO-8859-1 Japanese ja EUC-JP Korean Hindi ko hi UTF-8 Vietnamese vi UTF-8 EUC-KR Your program can be invoked with option: -a. In this case, it must print all the language names in file argument_file in alphabetical order, in this format: Languages in this file: first 3 name in alphabetical order 4. Vietnamese vi UTF-8 Your program can be invoked with option: -a. In this case, it must print all the language names in file argument_file in alphabetical order, in this format: Languages in this file: first name in alphabetical order second name in alphabetical order last name in alphabetical order Example with file argument_file given above: Command line: python languages.py -a argument file Expected output: Languages in this file: Chinese English German Hindi Italian Janan 5. Korean Vietnamese In the case in which file argument_file is empty, your program must instead only print: No languages in this file Your program can be invoked with option: -c code. The code argument has the same format as the code field in the argument file. In this case, your program must search for the code in the argument file, and if it finds it, print the language name. This is an example with file argument_file given above: Command line: python languages.py -c it argument_file Expected output: Italian In the case in which your program cannot find the given code in the argument file (including the case where the argument file is empty), it must print: 6. Code code not present in this file Example with file argument_file given above: Command line: python languages.py -c fr argument_file Expected output: Code fr not present in this file Your program can be invoked with option: -s set. The set argument has the same format as the set field in the argument file. In this case, your program must search for all the matches between the set argument and the set field in the argument file, and print all the corresponding language names, in the order in which they appear in the file. This is an example with file argument_file given above: Command line: python languages.py s ISO-8859-1 argument_file Expected output: 7. 8. English Italian In the case in which your program cannot find the given set in the argument file (including the case where the argument file is empty), it must print: Character set set not present in this file Example with file argument_file given above: Command line: python languages.py -s ISO-8859-7 argument_file Expected output: Character set ISO-8859-7 not present in this file Your program can be invoked with option: -v. In this case, it must only print your name, surname, student ID and date of completion of your assignment, in a format of your choice. Please note that argument argument file is still required. No options can be used simultaneously. This means that your program can only be invoked with one of the options at a time. L3
Step by Step Solution
★★★★★
3.51 Rating (151 Votes )
There are 3 Steps involved in it
Step: 1
Solutions Step 1 The program starts with two functions readworldseriesfile and displayteams The readworldseriesfile function takes a filename as input and returns two dictionaries teams and years The ...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