Question: # This program will contain random number file writer to be read in the next program # Import random number so that random numbers may

# This program will contain random number file writer to be read in the next program

# Import random number so that random numbers may be generated

import random

filename = 'randomnum.txt' # Creating a file

file = open(filename, 'w')

while(True):

try:

n= int(input('How many random numbers do you want? '))

if n<=0:

print('Invalid input. no negative or 0 numbers just postive integers try again. How many random numbers do you want? ')

continue

except ValueError:

print(' The value you entered is invalid. Only numerical values are valid try again. ')

else:

break

while(True):

try:

low=int(input('What is the lowest the random number should be? '))

if low<=0:

print(' Invalid input. no negative or 0 numbers just positive integers try again. What is the lowest the random number should be? ')

continue

except ValueError:

print(' The value you entered is invalid. Only numerical values are valid try again. ')

else:

break

while(True):

try:

high=int(input('What is the highest the random number should be: '))

if high<=0:

print(' Invalid input. no negative or 0 numbers just positive integers try again. What is the highest the random number should be? ')

continue

except ValueError:

print(' The value you entered is invalid. Only numerical values are valid try again. ')

else:

break

print('The random numbers were written to ', filename)

for i in range(n):

n=random.randint(low, high)

file.write(str(n)+' ')

file.close()

How do I get the program to display the random numbers were written to the file. like the last code. When I run the program it just stops at the highest the random number should be. and make sure that it is written to the file.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!