Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a python file that: When the programs is run, the user should provide a command line argument which is an integer. The number should

Create a python file that:

  • When the programs is run, the user should provide a command line argument which is an integer. The number should be greater than or equal to 1. If the number is less than 1, the program should print a warning and exit immediately.
  • The number provided by the user should be used to create an array of that length. The array should then be filled with random integers from 1 up to and including 20.
  • Output a label that says "All values", and then in a loop, print the contents of the array. No more than 10 numbers should appear on a line. The numbers should be separated by a space. After 10 numbers appear on a line, the next numbers should appear on the next line.
    • Make the numbers line up. With outputting the a number, used a format string. Since the largest numbers in the array have 2 digits (10 to 20), every number needs to be printed so that it takes up two spaces. For example, if you want to output a number that has been assigned to the variable val, output it as:
       stdio.write("%2d" % val)
  • Next output a two-column table that shows the frequency of each value in the table.
    • Output a header labels "Value Count".
    • For each integer from 1 to 20 - the same range of numbers used to generate the random values in the array - count how many times a value appears.
    • If a number does not appear in the array, its count should be 0.
    • Output each value and its count. You will need to line up the numbers under the labels. For example, if you want to output a number that has been assigned to val, output it as:
       stdio.write("%5d" % val)
      This is the same as when we output all the values in the array, except we need to change the number from 2 to 5, since each of our column headers contain 5 letters. Don't forget the space between the columns. If you want to output two numbers at once, for example, x and y, do something like this:
       stdio.write("x=%5d, y=%5d" % (x, y))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions

Question

10. Are you a. a leader? b. a follower? _______

Answered: 1 week ago