Sweet Store

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Introduction:

This Python code provides a simplified system for managing a sweet store,
with features for purchasing sweets and an admin mode for viewing profits
and updating sweet prices. Utilizing the popular libraries matplotlib, pandas,
and numpy, this program offers users the ability to buy sweets, view profits,
and make necessary adjustments to sweet prices. The sweet store's
inventory and sales data are stored in a CSV file, ensuring seamless data
management and persistence. The program initiates with a welcoming
message, presenting users with a menu to select their desired action.

Dataset:-
The project uses a dataset stored in a CSV file named
"C:/Users/LENOVO/Downloads/sweet store.xlsx - Sheet1.csv".This dataset
contains information about the sweets available in the store, including
the name of the sweet, its price per kilogram, and the profit generated
from its sales. The "Profit" column likely gets updated dynamically as
customers make purchases. The code accesses and modifies this
dataset using the pandas library, allowing for the management of
inventory, prices, and profits.

CSV FILE:-
CSV FILE NOTEPAD VIEW:

Code structure:
The provided code follows a structured approach that can be defined as
follows:

1. Imports: The code begins by importing necessary libraries, including


matplotlib, pandas, and numpy, to enable data manipulation and
visualization.
2. Reading Data: The program reads a dataset from a CSV file using the
pandas library and stores it in a dataframe named 'df'. The data
includes information about the sweet store, such as sweet names,
prices, and profits.
3. Welcome Message: A welcome message is displayed at the beginning
of the program, providing a friendly greeting to the users.
4. Function Definition: A function named 'choice' is defined to present a
list of options to the user, including buying sweets, accessing the
admin mode, or exiting the program.
5. Data Handling: Two lists, 'sweet_name' and 'price', are populated with
data extracted from the dataframe 'df'. These lists store the names and
prices of the available sweets in the store.
6. Function for Calculations: The code defines a function 'calculate' to
compute the total price based on the selected sweet and its weight.
7. Main Program Execution: The program enters a while loop that
executes until the user chooses to exit. Within this loop, the user's
input is processed to perform corresponding actions, including buying
sweets and accessing the admin mode.
8. Data Saving: If any changes are made during the program execution,
the updated dataframe 'df' is saved back to the original CSV file to
ensure that the changes are persisted for future use.

This organized structure ensures that the code performs its intended
functions while maintaining readability and ease of maintenance.
Code :
import matplotlib.pyplot as plt
import pandas
import numpy

df = pandas.read_csv( )
print("***WELCOME TO CHHAPPAN BHOG ***")
def choice():
print("""Enter your choice:
1. Buy sweet
2. Admin mode
3. Exit""")

sweet_name = []
price = []

for (i, j) in df.iloc[:, [1,2]].iterrows():


sweet_name.append(j.iloc[0])
price.append(j.iloc[1])

def calculate(no, weight):


result = price[no] * weight
return result

w = 0
while w == 0:
choice()
i = int(input(""))

if i == 1:
a = {}
p = 0
q= 0
while q == 0 :
for b in range(len(price)):
print(b, ".", sweet_name[b], "------>
Rs.", price[b], "per Kg")

print("\nTo Calculate Press {121}\n")


print("Your total price is:-", p)
k = int(input("Enter your choice:-"))
if k != 121 :
g = float(input("Enter in kg:-"))
p = p + calculate(k, g)
if sweet_name[k] not in a:
a[sweet_name[k]] = calculate(k, g)
else:
a[sweet_name[k]] += calculate(k, g)

df.iloc[k, 3] = df.iloc[k, 3] +
calculate(k, g)

if k == 121:
print("Your bill:-")
for c in a:
print(c, " ", a[c])
print("Your total price is:-", p)
print("***Thank you for shopping***")
w += 1
q += 1

df.to_csv("C:/Users/LENOVO/Downloads/sweet store.xlsx -
Sheet1.csv", index_col=0)

elif i == 2:
print("""Enter your choice:-
1. View profit
2. Change price of sweet
""")
f = int(input(" "))

if f == 1:
profit = df['profit']
x = numpy.arange(len(profit))
plt.bar(x, profit)
plt.xticks(x, df.sweet_name)
plt.xlabel("Sweet Name")
plt.ylabel("Profit")
plt.title("Store profit")
plt.show()
w+=1
else:
print("******SWEET SHOP MENU******")
for b in range(len(price)):
print(b, ".", sweet_name[b], "------>
Rs.", price[b], "per Kg")
y = int(input("Enter your choice:-"))
u = int(input("Enter the new price per
kg:-"))
df.iloc[y, 2] = u
print("Successful updated:-\n")
print(df.iloc[:, [1, 2]])
df.to_csv("C:/Users/LENOVO/Downloads/sweet
store.xlsx - Sheet1.csv", index=False )
w+=1

elif i == 3:
print("Exit")
w += 1
break

else:
print("Enter a valid option")
w+=1
Output:
(For option 1)
(For option 2)
(For option 2 if we go to admin mode)

(For option 3)
Conclusion:
The provided Python script presents a simple yet effective system for
managing a sweet store, combining functionalities for both customers and
administrators. The code enables users to interact with the store, facilitating
the purchase of various sweets and providing an admin mode for
overseeing profits and adjusting sweet prices as needed. Leveraging
libraries such as matplotlib, pandas, and numpy, the program ensures
seamless data handling and visualization, while the utilization of a CSV file
allows for the persistent storage and management of the store's inventory
and sales data. By encapsulating different functionalities within well-defined
functions and employing a structured approach, the code ensures clarity
and ease of modification, making it a practical and scalable solution for
sweet store management.This code can be further expanded or customized
to meet specific requirements and explore additional features.

You might also like