I need to generate a random number which I'll call x, and then generate x amount of numbers that are also random. I'm trying a for loop to no avail. There's more to the assignment but I feel like I'm at a roadblock till I figure this out.
My code:
def main():
import random
numbers_file=open('numbers.txt','w')
file_size = random.randint(4,7)
for x in range(file_size):
x = random.randint(5,19)
numbers_file.write(str(x))
print (file_size)
print (x)
main()
The print commands at the bottom are only there to test it as I need to write the random numbers to a file afterward.
Aucun commentaire:
Enregistrer un commentaire