I want to enter 5 different random numbers in the text file, but I can only do that. I don't know how to fix it, so can I ask for some advice? It's only been three weeks since I learned Python, so I don't know what it is.ㅠ<
python
import random
# Five random integers are pre-made and stored.
randomNums = (str(random.randint(1, 500)) for _ in range(5))
with open('random.txt', 'w') as wf:
'''
1
2
3
A string is created and stored in line units as shown in .
'''
wf.write('\n'.join(randomNums))
Write the code with num = random.radint (1,500)
and the random value you received at the end (here, 184) goes in 5 times. Define num as a list, not a variable, and num.I think you can get it by append.
© 2024 OneMinuteCode. All rights reserved.