'Python code to write to a CSV file using a loop

I am novice with Python coding. I am having some issue to send data file into CSV file. I am not sure why it's not being sent the way it's being printed. I couldn't manage to correct way looping. What did I miss in the code?

Image 1: shows how newline is being printed on right manner. However, when I use the for loop down it's sending the file like image 2. What did I mistake and how to resolve to send exactly the same as showing into print data?

Image:1

enter image description here

Image:2

enter image description here

Image:3

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source