Q. Write a Python program to create a csv file (Itemnew.csv) same as the previous program, but with a delimiter character as pipe (|)
Answer :-
import csv file = open("Itemnew.csv","w") itemwriter = csv.writer( file , delimiter = "|" ) while True : itemno = int(input("Enter item Number (for quit enter -1 ):- ")) if itemno == -1 : break name = input("Enter Name of item :- ") pri = float(input ("Enter price of item :-")) cat = input("Enter Category of item :- ") lst = [ itemno, name, pri, cat ] itemwriter.writerow( lst ) print() print("Created Successfully !!") file.close()
Output :-
Enter item Number (for quit enter -1 ):- 41286
Enter Name of item :- Pathwalla
Enter price of item :-999.99
Enter Category of item :- Website
Enter Name of item :- Pathwalla
Enter price of item :-999.99
Enter Category of item :- Website
Enter item Number (for quit enter -1 ):- 7966
Enter Name of item :- Portal Express
Enter price of item :-215.9
Enter Category of item :- Youtube
Enter item Number (for quit enter -1 ):- 76895
Enter Name of item :- Computer Portal
Enter price of item :-145.7
Enter Category of item :- Youtube
Enter item Number (for quit enter -1 ):- 87456
Enter Name of item :- Python
Enter price of item :-285.9
Enter Category of item :- Programing language
Enter item Number (for quit enter -1 ):- -1
Created Successfully !!
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )