This is a two part question. In my first program everything works ok. I\'m havin
ID: 3542827 • Letter: T
Question
This is a two part question. In my first program everything works ok. I'm having trouble with the second one:
7. Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 100. The application should let the user specify how many random numbers the file will hold.
here is what i have. so far no problems running this part:
# import the random module
import random
# define the main function
def main():
# open a file for writing and assign it to the variable random_numbers.
# this will reference the file object
random_numbers = open('ran_numbers.txt', 'w')
# get the number of random numbers to be generated
qty_numbers = int(input('How many random numbers should be written to the file? '))
print('Your list of random numbers are: ')
# create a loop to generate the random numbers in the quantity specified
for count in range (qty_numbers):
number = random.randint(1,100)
# print the list of random numbers
print(number)
# convert the numbers to a string and write them to the file
random_numbers.write(str(number)+ ' ')
# close the file
random_numbers.close()
# tell the user that the numbers have been written to the file name.
print('Your list of random numbers have been written to the file named')
print('ran_numbers.txt')
# call the main function
main()
The second file is where i'm having trouble
8. This exercise assumes you have completed programming exercise 7, random number file writer. Write another program that reads the random numbers from the file, display the numbers, and then display the following data:
-the total of the numbers
-the number of radom numbers read from the file
Explanation / Answer
https://dl.dropboxusercontent.com/u/38105421/problem.py
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.