Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(PYTHON) In completing this task, you will need to use the following constructs:

ID: 3672105 • Letter: #

Question

(PYTHON)

In completing this task, you will need to use the following constructs:
1. Random number generation

2. WHILE loops

3. File processing
Bolded concepts will be covered as needed by the TA.
In this task, you will write a series of random numbers to a text file called "random_numbers.txt". The basic algorithm for this process is described below:
1. Ask user for the number or random numbers to generate

2. Ask the user for the minimum possible value that can be generated

3. Ask the user for the maximum possible value that can be generated

4. Write the requested number of random numbers to the text file.

Here's my program's output:
Enter the amount of numbers to generate: 5

Enter the minimum value that a random number can be: -100

Enter the maximum value that a random number can be: 100

And the resulting file:

-4

19

-16

-15

-22

Explanation / Answer

#!/usr/bin/python
import random

def randomNumberInRange(x,y) :
   return random.randrange(x,y);

def main():
   print "Enter the amount of numbers to generate:"
   n = input()
   print "Enter the minimum value that a random number can be:"
   min = input()
   print "Enter the maximum value that a random number can be:"
   max = input()

   f = open('numbers.txt','w')
   for i in range(0,n) :  
       print(randrange(x,y))
   f.close()

main()