Project on Core Python:
Medical Shop and Pharmacy Billing System

Introduction

This Python project aims to calculate the total bill for customers purchasing medicines from a pharmacy. It also includes a loyalty points system where customers can earn and redeem points based on their purchases and their purchase history.

Prerequisites

  • Python 3.x
  • Basic understanding of Python programming, loops(for loops), and conditional statements.

Learning Objectives

Upon completing this project, the user will be able to:

  • Understand how to use ‘for loops’ and conditional statements ‘if else, elif and ‘if ladder’ in Python.
  • Take the input from the user and perform calculations based on it.
  • Implement a basic loyalty points system.

Installation Guide

Install Python 3.x from Python’s official website.

Project Steps

  1. Initialize Variables: Initialize variables for the number of shop visits from the user, his loyalty points, and other counters.
  2. User Input for Shop Visits: Prompt the user to enter how many visits were made to the shop.
  3. Calculate Bill and Points: For each visit, calculate the total bill and loyalty points based on the types and quantities of medicines purchased.
  4. Calculate Redeemable Points: If the points are equal or greater than 10 in the last visit then the user can redeem the points.
  5. Discount Calculation: The value of one point is Rs 25, calculate the total discount from the second visit by multiplying loyalty points by 25 and if the discount is greater than or equal to the Bill of the current purchase then the discount can be implemented.
  6. Redeem Points: Offer the option to the user of how many points he wants to redeem, from the second visit made to the pharmacy and calculate the final bill accordingly.

Code

				
					shopvisit= int(input("No. of visits"))
point=0
for i in range(1,shopvisit+1):
    print("\n\nshopvisit",i)
    total = 0
    medt=int(input("Enter how many types of medicines customer wants to purchase "))
    medqbill = medt
    if medt > 0:
        for j in range(1,medt+1):
            print("medicine type",j)
            medq=int(input(f"Enter medicine type{j} quantity "))
            if medq > 0:
                medc=float(input(f"Enter medicine type{j} cost "))
                perMediTotal = medq*medc
                total += perMediTotal
            else: 
                print(f"Wrong Input: Quantity entered for type{j} medicine is zero")
                medqbill -= 1
        curpoint=total//100
        if medqbill > 0:
            print("Bill is in",i,"visit",total)
            print("points earned in",i,"visit",curpoint) 
            if i==1: 
                point=curpoint
            elif(i>1):
                if(point>=10):
                    pointvalue=point*25
                    print("If customer want to redeem his points")
                    ans=input("Enter y/n: ")
                    if(ans=="Y") or (ans=="y"):
                        print("Stored points are ", point, "and their value is",pointvalue)
                        print(f"According to your current bill maximum redeemable points are {total//25} and their value is {25*(total//25)}")
                        if(total//25) > 0:
                            redpoint=int(input("How many points you want to redeem "))
                            if(redpoint<=point):
                                dis=redpoint*25
                                if(dis <= total):
                                    FB=total-dis
                                    point-=redpoint                    
                                    point+=curpoint
                                    print("Total Bill with redeeming",redpoint,"points",FB)
                                else: 
                                    print("Discount is more than total, redeeming not possible")
                                    point+=curpoint
                            else:
                                print("Wrong Input: Redeem points given are greater than points") 
                                point+=curpoint
                        else:
                            print("No points to redeem")
                            point+=curpoint
                    else:
                        print("Total Bill without redeeming is",total)
                        point=curpoint+point
                else: 
                    FB=total
                    point=point+curpoint
                    print("Total Bill when redeeming not possible ",FB)
            else:
                print("Stored point are not sufficient to redeem")
                point=point+curpoint
            print("Total points from last visit purchase",point)
        else:  
            print("No bill generated since user didn't purchase anything")
    else:
        print("Wrong Input: Number of medicine to be purchase are given zero")

				
			

Code

				
					shopvisit= int(input("No. of visits"))
point=0
for i in range(1,shopvisit+1):
    print("\n\nshopvisit",i)
    total = 0
    medt=int(input("Enter how many types of medicines customer wants to purchase "))
    medqbill = medt
    if medt > 0:
        for j in range(1,medt+1):
            print("medicine type",j)
            medq=int(input(f"Enter medicine type{j} quantity "))
            if medq > 0:
                medc=float(input(f"Enter medicine type{j} cost "))
                perMediTotal = medq*medc
                total += perMediTotal
            else: 
                print(f"Wrong Input: Quantity entered for type{j} medicine is zero")
                medqbill -= 1
        curpoint=total//100
        if medqbill > 0:
            print("Bill is in",i,"visit",total)
            print("points earned in",i,"visit",curpoint) 
            if i==1: 
                point=curpoint
            elif(i>1):
                if(point>=10):
                    pointvalue=point*25
                    print("If customer want to redeem his points")
                    ans=input("Enter y/n: ")
                    if(ans=="Y") or (ans=="y"):
                        print("Stored points are ", point, "and their value is",pointvalue)
                        print(f"According to your current bill maximum redeemable points are {total//25} and their value is {25*(total//25)}")
                        if(total//25) > 0:
                            redpoint=int(input("How many points you want to redeem "))
                            if(redpoint<=point):
                                dis=redpoint*25
                                if(dis <= total):
                                    FB=total-dis
                                    point-=redpoint                    
                                    point+=curpoint
                                    print("Total Bill with redeeming",redpoint,"points",FB)
                                else: 
                                    print("Discount is more than total, redeeming not possible")
                                    point+=curpoint
                            else:
                                print("Wrong Input: Redeem points given are greater than points") 
                                point+=curpoint
                        else:
                            print("No points to redeem")
                            point+=curpoint
                    else:
                        print("Total Bill without redeeming is",total)
                        point=curpoint+point
                else: 
                    FB=total
                    point=point+curpoint
                    print("Total Bill when redeeming not possible ",FB)
            else:
                print("Stored point are not sufficient to redeem")
                point=point+curpoint
            print("Total points from last visit purchase",point)
        else:  
            print("No bill generated since user didn't purchase anything")
    else:
        print("Wrong Input: Number of medicine to be purchase are given zero")

				
			

Code Explanation

  • shopvisit= int(input(“No. of visits”)): Take input of the number of visits from the user.
  • for i in range(1,shopvisit+1): For Loop through each visit to calculate the bill and points.
  • medt=int(input(“Enter how many types of medicines customer wants to purchase “)): Gets the types of medicines the customer wants to purchase.
  • total += perMediTotal: Adds the cost of each medicine to the total bill.
  • curpoint=total//100: Calculates the loyalty points based on the total bill.
  • if(total//25) > 0: Condition to check if the maximum redeemable points based on the history of purchases from last visit are greater than zero.
  • if(redpoint<=point): Condition for checking if the points that user wants to redeem should be less than and equal to total points.

Flow Chart explaining this Python Project

Flowchart of Python project - Medical Shop and Pharmacy Billing System

Pseudo Code explaining this Python Project

				
					Initialize shopvisit to User Input ("No. of visits")
Initialize point to 0

FOR i from 1 to shopvisit
    PRINT "shopvisit", i
    Initialize total to 0
    Initialize medt to User Input ("Enter how many types of medicines customer wants to purchase")
    Initialize medqbill to medt
    
    IF medt > 0 THEN
        FOR j from 1 to medt
            PRINT "medicine type", j
            Initialize medq to User Input ("Enter medicine type[j] quantity")
            
            IF medq > 0 THEN
                Initialize medc to User Input ("Enter medicine type[j] cost")
                Calculate perMediTotal as medq * medc
                Update total by adding perMediTotal
            ELSE
                PRINT "Wrong Input: Quantity entered for type[j] medicine is zero"
                Decrement medqbill by 1
            END IF
        END FOR
        
        Calculate curpoint as total // 100
        
        IF medqbill > 0 THEN
            PRINT "Bill is in", i, "visit", total
            PRINT "points earned in", i, "visit", curpoint
            
            IF i == 1 THEN
                point = curpoint
            ELSE IF i > 1 THEN
                IF point >= 10 THEN
                    Calculate pointvalue as point * 25
                    PRINT "If customer wants to redeem his points"
                    Initialize ans to User Input ("Enter y/n")
                    
                    IF ans is 'y' or 'Y' THEN
                        // Redemption logic here
                    ELSE
                        PRINT "Total Bill without redeeming is", total
                        point = point + curpoint
                    END IF
                ELSE
                    PRINT "Total Bill when redeeming not possible", total
                    point = point + curpoint
                END IF
            END IF
        ELSE
            PRINT "No bill generated since user didn't purchase anything"
        END IF
    ELSE
        PRINT "Wrong Input: Number of medicine to be purchased are given zero"
    END IF
END FOR

				
			

Pseudo Code explaining this Python Project

				
					Initialize shopvisit to User Input ("No. of visits")
Initialize point to 0

FOR i from 1 to shopvisit
    PRINT "shopvisit", i
    Initialize total to 0
    Initialize medt to User Input ("Enter how many types of medicines customer wants to purchase")
    Initialize medqbill to medt
    
    IF medt > 0 THEN
        FOR j from 1 to medt
            PRINT "medicine type", j
            Initialize medq to User Input ("Enter medicine type[j] quantity")
            
            IF medq > 0 THEN
                Initialize medc to User Input ("Enter medicine type[j] cost")
                Calculate perMediTotal as medq * medc
                Update total by adding perMediTotal
            ELSE
                PRINT "Wrong Input: Quantity entered for type[j] medicine is zero"
                Decrement medqbill by 1
            END IF
        END FOR
        
        Calculate curpoint as total // 100
        
        IF medqbill > 0 THEN
            PRINT "Bill is in", i, "visit", total
            PRINT "points earned in", i, "visit", curpoint
            
            IF i == 1 THEN
                point = curpoint
            ELSE IF i > 1 THEN
                IF point >= 10 THEN
                    Calculate pointvalue as point * 25
                    PRINT "If customer wants to redeem his points"
                    Initialize ans to User Input ("Enter y/n")
                    
                    IF ans is 'y' or 'Y' THEN
                        // Redemption logic here
                    ELSE
                        PRINT "Total Bill without redeeming is", total
                        point = point + curpoint
                    END IF
                ELSE
                    PRINT "Total Bill when redeeming not possible", total
                    point = point + curpoint
                END IF
            END IF
        ELSE
            PRINT "No bill generated since user didn't purchase anything"
        END IF
    ELSE
        PRINT "Wrong Input: Number of medicine to be purchased are given zero"
    END IF
END FOR

				
			

Challenges and Solutions

Invalid Input: The code handles invalid inputs by displaying an error message and not including them in the bill or points calculation.

Testing

Run the code and provide valid inputs when prompted. Verify that the bill and points are calculated correctly, and the option to redeem points works as expected.

Conclusion

This project demonstrates how to implement a simple billing and loyalty points system using Python. It covers essential Python concepts like loops, conditional statements, and user input.

Additional Resources

FAQs

1. What happens if I enter an invalid number of medicines or quantity?
The program will display an error message and will not include it in the bill or points calculation.

2. How are points calculated?
Points are calculated based on the total bill. One point is earned for every 100 units of currency in the bill.

Project and Documented by Nimisha Agrawal, Team edSlash Coding Hub.