TakeHomeQuiz - UTF-8''SuperQuiz.pdf ITSE 1359 This is a comprehensive quiz to test and evaluate your knowledge on Python. It is composed of two parts and it must be done individually. The purpose of...






TakeHomeQuiz - UTF-8''SuperQuiz.pdf ITSE 1359 This is a comprehensive quiz to test and evaluate your knowledge on Python. It is composed of two parts and it must be done individually. The purpose of this script is to process files, store them into a data structure (i.e., a list), define functions that will process items, and then report analysis and calculations into a file. ( PART I (10 POINTS) ) Create a script called partI.py. In this script, define the following functions 1. printOptions(): a function that will display the following message: >python3 partI.py [-option] [arguments] [-a]: read from argument [argument l]: name of file desired to read [argument 2]: name of file desired to write [argument 3]: target desired to fin on argument 1 [-i]: interact with user (no arguments needed) [ -r ] : generate random file [argumentl] corresponds of filename [argument2] corresponds to how many numbers to generate [argument3] corresponds to start number [argument4] corresponds to end number 2. readFile(): will take a string filename as a parameter, and it will return a list. Each element of the list represent a line from the file filename. 3. writeToFile(). Will take a string filename as a parameter and a list mylist as a parameter. The purpose of this function is to write in the file "filename ", the contents of mylist. 4. (optional) validateFile(): Will take a string filename as a parameter. The purpose of this file is to check if the filename exists or not . In case the file exists, the function will return True, otherwise will return False 5. calculateSum(): will take a list of values, mylist containing numeric values. The purpose of this function is to calculate the sum of all the items in the list. 6. calculateAverage(): will take a list of values, mylist containing numeric values. The purpose of this function is to calculate the average of all the items in the list. 7. findTheLargest():will take a list of values, mylist containing numeric values, and it will return the largest value from the argument s. 8. findTheSmallest(): will take a list of values, mylist containing numeric values and it will return the smallest value from the argument s. ( 2 ) 9. count Total Ti me s ( ) : The function will take a target as an argument and a list as argument. Your function will count the total number of times the target appears in the list. 10. f i nd St d De v () : This function will take a list a of numeric values as a parameter. The function shall return the standard deviation Sx of the values in the list a. Remember that the standard deviation can be calculated as follow: where: · N = the total numbers in the data file · x = the mean of x; (also known as the average) · x; = Each of the values in the array 11. genera teRandom () : The function will take 4 arguments: · filename: the name of the file where a random number will be appended · total: the total number of random numbers to generate randomly · st art: the starting random number to be generated · end: the ending random number to be generated PART III You will need to use part I . pytodevelop Part II. Create a Python script called part II .py.This script will be in charge of interact with the user through two different modes depending on the command provided as the argument when you execute the script as fo llows : > python3 part II .py [ - o p t i o n ] [ ar gume nt s ] 1. where the option can be one of the three following options: a. -a: will read from arguments b. - i: will interact from user c. - r: will generate a file with random numbers 2. If the option is -a then you need to provide arguments (two file names) 3. If the option is -i then you don't need to provide any arguments 4. If the user did not provide any option, your script shall print the following error message Pl e a s e provide a valid opt i on : python3 partII.py [ - op t i on ] [ ar gume nt s ] And the function printOptions ()from Part I shall be called displaying the possible options for the program ( READING COMMNAD LINE ARGUMENTS (I. E ., - A) ) You should run your program with the command shown in previous section. Where: · -a: means you will process the information from the command line · [argumentl] is the name of the file your program will read · [argument2] is the name of the file your program will write the results · [argunmet3] is the target interested to find Your script shall use the functions defined in Part I. The file specified on argument2 represents the output file, where it will report the analysis of functions 5 -10 from Part I. ( INTERACTING FROM USER (-1) ) If user entered the option -i as argument, then you will request for: >Enter the input file name >Enter the output file name >Enter the target interested to find And then perform the functions 5 -10 from Part I and report the results on the output file ( GENERATING FILE WITH RANDOM NUMBERS (-R) ) If user entered the option -r ONLY to generate a file with random numbers. Notice that this option can be used regardless of option -a and/or - i. 1. [argumentl]corresponds of filename 2. [argument2]corresponds to how many numbers to generate 3. [argument3]corresponds to start number 4. [argument4]corresponds to end number EXAMPLE >python3 partII.py -r random.txt 5 1 11 Means that will generate a file called random.txt and it will contain 5 numbers . The numbers will be generated randomly and may have values between 1 and 10. ( USER INTERACTION AND CASE HANDLING ) Whether the user picked the -a or the - i option, the user is allowed to make five mistakes in total while entering information to the program (i.e., there exist a file to read). Notice that the user will continue entering the information in a repeatable fashion. If the user entered five mistakes in total, a comment shall be displayed as fo llows : Please make sure you read documentation before using this script and your program shall terminate immediately, otherwise will continue printing the message suggested on Part 11.3
Apr 29, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here