How to write lines (for loop) with specific format with different variables in python (mix between string and integers ) in Python

Question:

I would like to write the following lines as it is but with different variables (a,z and g) as the following:
For i In {1:a+1}
b~{i} = z+(i-1)*g;
EndFor

I mean I have a code defines the a,z,g (but they might be different each time): I do not want python to calculate the loop, I just wanna the above lines to be written with same (loop format) in a text file
here as the code I think .. any suggestion or documentation to help me …
Not sure how could I write what i want with different variables

import numpy as np
a=3
z=5
g=2
fileID                                =    open(output.dat,"w")
fileID.write('%s%s%d%s%d%s%d%s%d%s n'% 
 ('Point(1)=','{',0,',',0,',',a,',',z,'}'))
 fileID.write('n')
 # I NEED TO WRITE HERE the following for loop but with different a, z and g ?
For i In {1:a+1}
b~{i} = z+(i-1)*g;
EndFor

Thanks,

Asked By: Sci_tech

||

Answers:

Try this

import numpy as np
a=3
z=5
g=2
fileID = open('output.dat',"w")
s = "For i In {1:"+str(a)+"+1}nt"+str(z)+"~{i} = z+(i-1)*"+str(g)+";nEndFor"
fileID.write(s)
fileID.close()
Answered By: roshan ok
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.