Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In python Write two Python scripts named gen.py and stats.py and one deliverable named report.pdf in PDF format. You are not allowed to use advanced

In python

image text in transcribed

image text in transcribed

image text in transcribed

Write two Python scripts named gen.py and stats.py and one deliverable named report.pdf in PDF format. You are not allowed to use advanced libraries such as numpy and pandas. In fact, you probably only need to use the following libraries: math, os, random, re, and sys. 1. (40 points) gen.py - takes inputs from the user to generate a CSV file by: a. (5 points) Take inputs from the user in the following order: i. The number of columns - with "Enter the number of columns:". The input is a single integer. ii. The number of rows - with "Enter the number of rows:". The input is a single integer. iii. The minimum value - with "Enter the minimum value:". The input is a single integer. iv. The maximum value - with "Enter the maximum value: ". The input is a single integer. v. The set of invalid values - with "Enter invalid values:". The input could either be empty, a single integer, or multiple integers separated by a space. vi. The random seed value - with "Enter the random seed value:". The input is a single integer. vii. The output CSV file name - with "Enter the output CSV file name: ". The input is a string. b. (10 points) Check the inputs in the following order: i. The number of columns must be positive. If not, print "The number of columns must be positive!". ii. The number of rows must be positive. If not, print "The number of rows must be positive!". iii. The minimum value must be less than or equal to the maximum value. If not, print "The minimum value must be less than or equal to the maximum value!". iv. Print "Invalid output CSV file name!" if the output CSV file name is invalid. The output CSV file name must begin with an alphanumeric character (i.e., A to Z (case insensitive) and 0 to 9), possibly followed by a combination of alphanumerical characters and a hyphen (i.e., -), must followed a dot, then ends with only either "CSv" or "CSV". Examples: Valid file names: a.csv, a1.csv, 1a.csv, a-1.csv, 1-a.CSV Invalid file names: .cSv, acsv, a.cSv, a.cSvv, a-.cSv, -a.csv All error messages must be printed in the order where the conditions were checked (and the errors were found), then the program terminates if there is any error. c. (20 points) Write the CSV file named according to the user's input. The file contains integers separated by a comma according to the number of columns, and by a new line according to the number of rows from the user. The integers are randomly generated between the minimum and the maximum values (inclusive) with the random seed value as specified by the user. Each integer that the value generated is in the invalid set is written as a blank (i.e., an empty string). Your CSV file should not contain any characters other than numbers, commas, and new lines. d. (5 points) If the output CSV file cannot be written, print "Cannot write {file name } " where {file name } is the name of the file as specified by the user. Otherwise, print "Written { path } ", where { path } is the absolute path that the file has been written. Example: - In Windows, if test.csv has been written to "C:\Users\Poom\Desktop", you should print "Written C:\Users\ Poom \ Desktop \ test. csv". - In most other OS, if test.csv has been written to "/home/poom", you should print "Written /home/poom/test.csv". Your program should be able to run on any OS, meaning that your program should correctly print the message regardless of where it runs, not just on your OS. You cannot simply append the file name to the path by using either a forward slash (i.e., ' / ') or a backslash (i.e., ' '). For example, if on Windows your program prints "Written "Written /home/poom\test.csv" even though you may have developed the program on Windows. a. (3 points) Check whether there are any supplied arguments from the command line. Print "Usage: python stats.py [FILE]" if there is none and terminate the program. b. (7 points) Open each file in the list of arguments. For any file that cannot be opened, print "Cannot read \{file name\} - skipped" where {file name } is the name of the file that cannot be opened, then continue down the next file in the list. For any file that can be opened but is empty, print "Empty - skipped" then also continue down the next file in the list. Print a horizontal line "_-_._-_.-_.-_" for every file that has been processed, including those that have been skipped. c. For each file that can be opened and is not empty, do the following in order: i. (5 points) print the file name in the first line and its content in the next lines. ii. (15 points) for each column, print "Column {n} " where {n} denotes the column number starting from 1; and in the next line, print "- \#values: {a} " where {a} is the number of valid values (i.e., not blank). If the number of valid values is positive, continue to print the following stats from the values in the subsequent lines: 1. "- sum: {b} " where {b} is the sum of the values. 2. "- min:{c} " where {c} is the minimum value. 3. "- max:{d} " where {d} is the maximum value. 4. "- avg: {e} " where {e} is the average value. 5. "- SD: {f} " where {f} is the standard deviation of the values. iii. (10 points) continue from the previous bullet. If the column contains some valid values, also print "- Frequency" after "_ SD: {f} ". Then, in the subsequent lines, print " { value\} : \{freq } " for each value in the list of valid values in the column, in an ascending order, where { value } is the value and { freq } is the number of times it appears in the column

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Draw a labelled diagram of the Dicot stem.

Answered: 1 week ago