Create an Invoice with Python

An invoice is a bill that serves as proof of a transaction between a buyer and a seller. In this article, I will walk you through how to create an invoice with the Python programming language.

Create an Invoice with Python

To create an Invoice with Python I will be using the basics of Python programming language. It is a beginner level task so it will help you to improve your coding skills. We don’t need to make use of loops here, just print statements and formatting is all we need for this task.

Also, Read – Python Projects with Source Code: Solved and Explained.

I will start by declaring six variables as the name of three products and their price, you can add more products to your list:

product1_name, product1_price = 'Books', 50.95
product2_name, product2_price = 'Computer', 598.99
product3_name, product3_price = 'Monitor', 156.89

Now let’s store the name and address of a company which is very important to show at the top of a receipt:

company_name = 'Thecleverprogrammer, inc.'
company_address = '144 Kalka ji.'
company_city = 'New Delhi'

Now I will store a greeting message in a variable to show at the end of the invoice, and then I will also create a border for the invoice:

message = 'Thanks for shopping with us today!'
# create a top border
print('*' * 50)

Now I will print the name of the company in a tabular format, we will not print and execute at this stage, To make it look better I will create lines after the address of the company in the format of “=”:

print('\t\t{}'.format(company_name.title()))
print('\t\t{}'.format(company_address.title()))
print('\t\t{}'.format(company_city.title()))
# print a line between sections
print('=' * 50)

Now let’s print the names, and price of the products in the tabular format:

print('\tProduct Name\tProduct Price')
# create a print statement for each item
print('\t{}\t\t${}'.format(product1_name.title(), product1_price))
print('\t{}\t${}'.format(product2_name.title(), product2_price))
print('\t{}\t\t${}'.format(product3_name.title(), product3_price))

Now again I will print a line using “=” and then I will print the total of the above products:

print('=' * 50)
# print out header for section of total
print('\t\t\tTotal')
# calculate total price and print out
total = product1_price + product2_price + product3_price
print('\t\t\t${}'.format(total))
# print a line between sections
print('=' * 50)

At last, I will pass the greeting message that we declared above:

print('\n\t{}\n'.format(message))
**************************************************
                Thecleverprogrammer, Inc.
                144 Kalka Ji.
                New Delhi
==================================================
        Product Name    Product Price
        Books           $50.95
        Computer        $598.99
        Monitor         $156.89
==================================================
                        Total
                        $806.83
==================================================

        Thanks for shopping with us today!

**************************************************

Summary

Now you can run your code, feel free to modify this program by adding more products. You can get the complete code used in this article to create an invoice with Python from below.

I hope you liked this article on how to create an invoice with the Python programming language. Feel free to ask your valuable questions in the comments section below.

Aman Kharwal
Aman Kharwal

I'm a writer and data scientist on a mission to educate others about the incredible power of data📈.

Articles: 1534

5 Comments

Leave a Reply