0

How To Export The Data Behind Print() To Text File In Python

Please Solve This Python Problem

20th May 2020, 1:30 PM
Bharat Mangal
Bharat Mangal - avatar
7 Respuestas
+ 1
Can you post your code showing your attempt at solving this please?
20th May 2020, 1:42 PM
Slick
Slick - avatar
+ 1
Yes
20th May 2020, 2:15 PM
Bharat Mangal
Bharat Mangal - avatar
0
Just a minute, gonna paste
20th May 2020, 2:17 PM
Bharat Mangal
Bharat Mangal - avatar
0
# SP=Selling Price # cgst=central govt gst # sgst=state govt gst import os import csv import sys busn=input("Enter Your Business Name ") item=input("Enter Item Name ") SP=float(input("Enter selling price of item "+item+": ")) gstRate=float(input("Enter GST Rate (%): ")) cgst=SP*((gstRate/2)/100) sgst=cgst amt=SP+cgst+sgst # Consumer will buy at this price print("\t",busn) print("\t INVOICE") print("\tItem:",item) with open('data.csv','w', print("\tPrice:",SP) print("\tCGST(@",(gstRate/2),"%):",cgst) print("\tSGST(@",(gstRate/2),"%):",sgst) print("\tAmount payable:",amt)
20th May 2020, 2:23 PM
Bharat Mangal
Bharat Mangal - avatar
0
i want the data which is going to print should be exported in a text file,,,,
20th May 2020, 2:24 PM
Bharat Mangal
Bharat Mangal - avatar
0
Okay well after you open a csv file youd need a csv writer. writer = csv.writer() I beleive. Then it needs to write an iterable of values. each value being a different cell in the same row. You may also want to make a list of the categories and write them first so theyll be at the top
20th May 2020, 2:29 PM
Slick
Slick - avatar
0
Then loop through with writer.writerow() or writer.writerows() depending on your setup.
20th May 2020, 2:34 PM
Slick
Slick - avatar