Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program, in a file called FrequencyOfNumbers.py, which uses the following functions to perform the required tasks: a function called createList which generates N

Write a program, in a file called FrequencyOfNumbers.py, which uses the following functions to perform the required tasks:

  1. a function called createList which generates N random integers between 1 to 15 and stores them in a one-dimensional list. Note: The value of N is to be obtained as input from the user and passed as a parameter to the function. An empty list should also be passed as a parameter to store the resulting list.
  2. a function called findFreq which, given a list of random numbers, creates and returns a new list (of size 15) with the frequency counts of each number from 1 to 15 (i.e., a list containing the number of times each number from 1 to 15 occurs in the given list). Note/Hint: This function should use a single loop only (you should not need a nested loop for this).
  3. a function called findPowers which, given the frequency count list, returns a new list containing each number, from 1 to 15, raised to the power of its frequency. For example, if frequencyCount[11] holds a frequency value of 3, then position 11 of the new list would be assigned the result of 123 since index 11 holds the frequency of 12. (Hint: Use math.pow to compute the product of a number 123 = 1728)
  4. a main function to test all the functions and print the corresponding lists produced.

The input/output from the program would be similar to:

Please enter the number of integers in the list: 30 The list of 30 random numbers between 1 and 15 is: [5, 3, 15, 7, 1, 10, 10, 6, 5, 13, 10, 11, 11, 10, 10, 1, 8, 1, 14, 3, 13, 13, 5, 1, 3, 10, 1, 4, 3, 13] The frequency counts of the numbers from 1 to 15 are: [5, 0, 4, 1, 3, 1, 1, 1, 0, 6, 2, 0, 4, 1, 1] The numbers from 1 to 15 raised to the power of their frequency are: [1.0, 1.0, 81.0, 4.0, 125.0, 6.0, 7.0, 8.0, 1.0, 1000000.0, 121.0, 1.0, 28561.0, 14.0, 15.0]

image text in transcribed

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_2

Step: 3

blur-text-image_3

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

Advances In Spatial And Temporal Databases 11th International Symposium Sstd 2009 Aalborg Denmark July 8 10 2009 Proceedings Lncs 5644

Authors: Nikos Mamoulis ,Thomas Seidl ,Kristian Torp ,Ira Assent

2009th Edition

3642029817, 978-3642029813

More Books

Students also viewed these Databases questions