0
i have the following text
1050 = N X 0
1260 = N X 0
1470 = N X 0
1680 = N X 0
1890 = N X 0
2100 = N X 0
2310 = N X 0
2520 = N X 0
2730 = N X 0
2940 = N X 0
3150 = N X 0
3360 = N X 0
3570 = N X 0
where ta "X" I want to sub-post for a random number from zero to nine
(random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9]))
to look like this
1050 = N 0 0
1260 = N 1 0
1470 = N 4 0
1680 = N 6 0
1890 = N 8 0
2100 = N 3 0
2310 = N 1 0
2520 = N 1 0
2730 = N 6 0
2940 = N 5 0
3150 = N 3 0
3360 = N 2 0
3570 = N 8 0
I don’t know how to apply
Read the file line by line (
open
), draw a number (random.choice
), replace the value ofX
(str.replace
) and write in the file (f.write
). Want to try?– Woss
I’ll try to do it and I’ll glue the result here
– felipe
I n got it I tried import Random open ('/Users/Felipe/Desktop/GH.txt','r') MM = (Random.Choice([1, 2, 3, 4, 5, 6, 7, 8, 9]) GH.replace('X','MM')
– felipe