(Jan-11-2022, 04:03 PM)Rasedul Wrote: Can you write the code please, I am new in python and learning.You should give a try when a get suggestion doesn't matter it it's a bad way or not work,just to show some effort
It's not need here to use csv module as pointed out,to show examples how it can be using csv module.
The same output as print().
import csv with open('op2.csv', 'w', newline='') as f: writer = csv.writer(f) var = 'hi' for x in range(2, 5): writer.writerow([f'{var}{x}'])
Output:hi2
hi3
hi4
A comma between variable and loop result.import csv with open('op2.csv', 'w', newline='') as f: writer = csv.writer(f) header = ['Word', 'Result'] var = 'hi' writer.writerow(header) for x in range(2, 5): writer.writerow([var, x])
Output:Word,Result
hi,2
hi,3
hi,4