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 : add_row(['<row1>','<row2>',....])
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:
Note: You can run this program on any python version except for python2 you just need to change the syntax of print().
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course