Below, I have a code that will use an inner loop and outer loop to create text file. I am wanting to have weight to increase by increments of 0.1 between the interval of 0.1 to 1.0. I am also wanting length to increase from 0, 40, 80, 160, 250, and 300. But the length will not increase to the next term until weight has reached 1.0 for the previous length.
The code below does not work. The txt files should look like weight_0.1_0_.txt and in it should be
weight of box 0.1
length of box 0
this should continue till the file weight_1.0_0_.txt and inside should be
weight of box 1.0
length of box 0
Once it reaches this value the next one should be weight_0.1_40_.txt and inside should be
weight of box 0.1
length of box 40
this should continue until all the lengths to 300 are satisfied. If anyone could help me with this code, I would deeply appreciate it.
lengths = [0,20,40,80,160,250,300]
for l in lengths:
Weight = 0.1
for i in range (10):
input = 'weight_' +str(Weight)+ '_length_' +str(lengths)+ '_'
file = open(input + '.txt','w')
file.write('weight of box ' +str(Weight)+ '\n')
file.write('length of box ' +str(lengths)+ '\n')
file.close()
Weight +=0.1
length = 1
With this code above, the resulting file would be for example
weight_0.1_[0,20,40,80,160,250,300]_.txt which is not correct and inside
the files would be
weight of box 0.1
length of box [0,20,40,80,160,250,300]