import random
myfile = open('numbers.txt', 'w')
file_size = random.randint(4,7)
for count in range(file_size):
numbers = random.randint(5,19)
myfile.write(str(numbers) + '\n')
myfile.close()
This what I have so far, but I need the numbers to be all odds and the right amount of odds that the "file_size" is telling the code. Each integer must be random, between 5 and 19 inclusive.
You can use random.randrange
which accepts optional step
parameter:
>>> import random
>>> random.randrange(5, 19+1, 2)
9
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments