One way that I know to go about this problem requires a bit of work,
first save the python code to a place where you can easily set up a file.
Now I am pretty lengthy with this and there are probably other ways but.
outfile = open ("STRING NAME.csv","w")
Will create the CSV file by "String Name" the .csv will make the file easier to open
outfile.write(value)
outfile.write(",")
will separate everything by commas
and at the end of each line that you want to write
outfile.write("\n")
will make a new line for the csv
outfile.close()
to finish it off
hope this helps
example of where I have used before
while h<=math.sqrt(float(d)):
if float(d/(h*h))!=float(int(d/(h*h))):
h=h+1
else:
j=h
h=h+1
if j==int(1) or int(d/(j*j))==1:
a=a
else:
if j/2==int(j/2):
a=a
else:
outfile.write(str(int(b)))
outfile.write(",")
outfile.write(str(int(c)))
outfile.write(",")
outfile.write(str(int(d)))
outfile.write(",")
outfile.write(str(int(g)))
outfile.write(",")
outfile.write(str(int(j)))
outfile.write(",")
outfile.write(str(int(d/(j*j))))
outfile.write(",")
print("b=",int(b)," and c=",c)
print(float(d)," has a square root of ",float(j)," rad ",float(d/(j*j)))
a=a+1
if a==16:
z=input("SO....")
if z==str("good"):
a=16
else:
a=1
print("Fui")
outfile.write("Bad")
outfile.write("\n")
while a==16 and p<10:
outfile.write("\n")
p=p+1
print("new line")
a=1
outfile.close()