For this programming assignment, you will write two programs. The first program will generate a file of random numbers and write them to a file. The user will be allowed to specify the range of values for the random numbers and the number of random numbers to generate.
The second program will allow the user to specify a filename that contains a series of random numbers. The program will read the numbers from the file and display each number. At the end of processing the file, the program will display the number of numbers read, the sum of the numbers, and the average value of the numbers.
I am primarily struggling with having the user input ranges.
Hello @maxharley7159186516, welcome to the forums! Unfortunately, we can’t directly help with class assignments here on the forums. We may be able to help guide your thinking if you can present it to us…
Hey there! My bad. I am primarily struggling with having users input the range. When I run the code, it runs my range questions the for the number of numbers the user requests to generate. I need to break that from the loop, but coded myself into a corner since I saved this step for last. Here is my current code:
userrangelower = int(input("What should the range’s lower bound be?: "))
userrangeupper = int(input("What should the range’s upper bound be?: "))
randomNumber = random.randint(userrangelower, userrangeupper)
numrandnumbers = int(input("How many numbers should the file hold?: "))
filewritetoopen = open(“randomNumbers.txt”, “w”)
for randnumbcount in range(1,numrandnumbers + 1):
filewritetoopen.write(str(randomNumber) + “\n”)
And before the filewritetoopen.write line, there should be randomNumber = randnumbers()
Sorry for the late reply, but I don’t quite understand your question. Could you rephrase it, please? Also, make sure to post code according to the formatting guide in this post.
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.