Skip to content
Related Articles

Related Articles

Creating a Receipt Calculator using Python

View Discussion
Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 17 May, 2022

A receipt calculator is generally a slip in which the total invoice along with their names is mentioned. We will use the class PrettyTable inside the prettytable library for making our receipt calculator.

What is PrettyTable ?

It is a class present inside prettytable library which help us to make relational tables in Python.  

Installation of library:

pip install prettytable

Generating PrettyTable :

Initialisation :
<table name> = PrettyTable(['<column1>','<column2>',....])

To add a row :

Approach :

There will be two columns: Item Name & Item Price. 

We will keep taking item name and item price (in new line) 
Until the user enters ‘q’ and store the price in another variable name ‘total’ initialized as 0. When user
Enters ‘q’, program will stop taking inputs and return the table along with the total amount specified at the end.

Below is the Implementation:


from prettytable import PrettyTable
print('--------------WELCOME TO XYZ Shop--------------\n')
table = PrettyTable(['Item Name', 'Item Price'])
total = 0
    name = input('Enter Item name:')
    # 'q' to exit and print the table
    if(name != 'q'):
        price = int(input('Enter the Price:'))
        # store all the prices in 'total'
        total += price
        table.add_row([name, price])
    elif(name == 'q'):
table.add_row(['TOTAL', total])
print('\nThanks for shopping with us :)')
print('Your total bill amount is ', total, '/-')


Note: You can run this program on any python version except for python2 you just need to change the syntax of print().

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!