0
i have the following text inside a.txt file
[ExpertSingle]
{
1050 = N X 0
1260 = N X 0
1470 = N X 0
1680 = N X 0
1890 = N X 0
2100 = N X 0
I want to turn "X" into numbers using Choice Ring to look like this
[ExpertSingle]
{
1050 = N 2 0
1260 = N 0 0
1470 = N 4 0
1680 = N 0 0
1890 = N 1 0
2100 = N 3 0
I made this code "copied from several videos I watched"
import random
import fileinput
file_name = 'C:/Users/Felipe/Desktop/GH.txt'
c3 = (random.choice([0, 1, 2, 3, 4]))
for line in fileinput.FileInput(file_name,inplace=1):
if 'X' in line:
line = line.rstrip()
line = line.replace('X','c3',1)
print (line)
I got this result kkk
[ExpertSingle]
{
1050 = N c3 0
1260 = N c3 0
1470 = N c3 0
1680 = N c3 0
1890 = N c3 0
2100 = N c3 0
I don’t know where I went wrong and I don’t know how to get the desired result can anyone help me please?
Instead of using C3 as a string, it would not be the case to put `line = line.replace('X',str(Random.Choice([0, 1, 2, 3, 4])),1)
– Felipe Avelar