Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help me with this Python question (Write a program to generate random numbers) You need to first import Python's random support. At the top of

Help me with this Python question

image text in transcribed

(Write a program to generate random numbers) You need to first import Python's random support. At the top of your file, put the line import random You will use the randint) method to generate the numbers. Use the input) function to ask the user how many numbers to generate. Also, ask for a range ( the largest integer to generate) (Loop to read and count numbers) Write a for loop with the range operator and use the random.randint) function to generate numbers. The randint) function takes 2 arguments. The first is the low end of the range of numbers to generate. The latter is the high end of the range. For each number, increment a dictionary entry for that integer (use the same pattern of code as we did when counting words with setdefault(and then an increment of the dictionary entry) (Loop and print counts) When that loop completes, loop for the numbers from 0 through the maximum number the user entered for the 'range'. Print the integer (key) and the count for that integer (Test code) Your code should produce the following output: 0: 0 1: 959 The above is 'notional'. Since numbers are random, every run will produce different output! Try a few different inputs. Have it generate 100 numbers from 0-9 (enter 10 for 'range'). Try '10000 numbers between 0-9 Take a look at the outputs and see how far off each count is from one tenth of the generated numbers. For example, generating 10000 numbers should mean each count should be about 1000 You will see some that are between 950 and 1000. Some will be between 1000 and 1050 or maybe more Figure out the range of counts relative to the 'expected' count. So for the example with 10000 number between 0-9, numbers like 1050 are +5% from the expected value. 950 is-596. So find the lowest and highest counts and calculate the percentage below and above the expected count. Do this for a run of 10000 numbers. Then try a run with 1000000. Do the percentages of variation get any smaller around the expected count (100000). Put a copy of the generated output for the two runs into comments at the head of the program file (below your name, id, and email along with the range of variance (-n%--m96)

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions

Question

What is the specific piece of work?

Answered: 1 week ago

Question

List and discuss methods of staff member evaluation.

Answered: 1 week ago