for row in rows:
writer.writerow(row)
That writes each element of
rows
on a separate line; it should be:
writer.writerow(rows)
Also you do not need all those extra square brackets, the list should simply be:
rows = [userr_name,passwordd,card_balance,0]
[EDIT]
My modified code:
import csv
userr_name=input("Enter your user name that you want to create:")
passwordd=input("Enter the strong password:")
card_balance=int(input("Enter the amount to be stored:"))
column_names = ["USERNAME","PASSWORD","CARD_BALANCE","PENDING_AMOUNT"]
rows = [userr_name,passwordd,card_balance,0]
with open('dataframe.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(column_names)
writer.writerow(rows)
And the results:
C:\Users\rjmac\Documents\VSCode\Python>python cp.py
Enter your user name that you want to create:Richard
Enter the strong password:password123
Enter the amount to be stored:45
C:\Users\rjmac\Documents\VSCode\Python>type dataframe.csv
USERNAME,PASSWORD,CARD_BALANCE,PENDING_AMOUNT
Richard,password123,45,0
[/EDIT]