Gaurav Kshitiz Acharya
Gaurav Kshitiz Acharya
Gaurav Kshitiz Acharya
Assessment Type
60% Individual Course Work
Semester
Summer Semester 2024
Word Count:
I confirm that I understand my coursework needs to be submitted online via Google Classroom under
the relevant module page before the deadline in order for my assignment to be accepted and marked.
I am fully aware that late submissions will be treated as non-submission and a mark of zero will be
awarded.
Table of Contents
1. Introduction ............................................................................................................ 1
4. Program ................................................................................................................. 9
Reference................................................................................................................. 18
Appendix .................................................................................................................. 19
Table of Figures
Figure 1 ...................................................................................................................... 4
Figure 2 ...................................................................................................................... 5
Figure 3 ...................................................................................................................... 6
Figure 4 ...................................................................................................................... 7
Figure 5 ...................................................................................................................... 7
Figure 6 .................................................................................................................... 10
Figure 7 .................................................................................................................... 10
Figure 8 .................................................................................................................... 11
Figure 9 .................................................................................................................... 11
Figure 10 .................................................................................................................. 13
Figure 11 .................................................................................................................. 14
Figure 12 .................................................................................................................. 15
Figure 13 .................................................................................................................. 16
Table of Tables
Table 1 ..................................................................................................................... 13
Table 2 ..................................................................................................................... 14
Table 3 ..................................................................................................................... 15
Table 4 ..................................................................................................................... 16
1. Introduction
The goal of this coursework and this code is to make an error errorless program which
give us proper output. This program is being made for a shop their customers and
produce a bill in each purchase and sell of furniture. For example, designing an
interface to manage furniture, receipt making etc.
1. Firstly, I think of creating a text file that stores furniture details like furniture
quantity, furniture quality, price of furniture that are available on the ship.
2. Afterwards, I will develop a function that reads the text file, like shop name and
shop details will be also created.
1
3. Then I made a table that shows how much furniture available in shops by
reading the text file that I created at the first. Moreover, I also created how to
operate and be eco-friendly with the program.
4. After customer select options as per their needs, the user can either sell or
purchase or exit the program. To meet those criteria, I separately developed
different functions for selling and purchasing furniture and exiting the program
interface.
5. After finishing the process of selling and purchasing of furniture to create receipt
we can say bill I created function that generate bill in text file format as well.
By following objectives, I successfully developed a program for the furniture shop that
sells and purchase furniture.
2
2. Discussion and Analysis
2.1 Algorithm
Step1: Start
Step 2: Print the detail of the shop like contact information, shop name and location
etc.
Step 3: Displays the furniture and it’s details by reading the text file where the furniture
details are stored.
Step 5: After that, the program will show the option of sell purchasing and existing the
system.
Step 6: According to the user selection sell and purchase process caried out.
Step 7: In both sale and purchase process username address and contact number will
be asked.
Step 8: Now the system will create an invoice in text file format and print the bill in the
terminal.
Step 9: After printing the invoice, it will show the step 5 process. If user select sale or
purchase option, the same process will again be carried out. If user select option 3,
they will exit from system.
3
2.2 Flowchart
Figure 1
4
Figure 2
5
Figure 3
6
3. Data Structure
Data structure is way of managing and organizing data so that we can easily
accessed those data more efficiently as per our needs. Every programming
language has its own data structure and data structure are basic and fundamental
concept of any programming language. Like other programming languages python
also support data structure. Python has following data structure:
1. Lists
2. Dictionary
3. Tuple
4. Set
1. List
Lists are similar as arrays. It is an ordered collection of data. Lists are very flexible
because list can store data with different data types. Data stored is a list can be
accessed by index. Python lists are mutable so we can insert, delete, and change
data anytime. I have also implemented the lists in my project. Using list to store data
is very useful. I can easily manipulate those data as I needed.
Figure 4
2. Dictionary
Dictionary is an unordered collection of data and values. Dictionary stores data in the
base of key value pair. We can access these values using keys, and each key must
be unique. Like list dictionary is also mutable and we can perform update, change,
insert, and remove operations.
Figure 5
7
3. Tuple
It is an immutable data structure in python programming language. We cannot add or
remove and data from tuple once created. Just like a list tuple can store various data
types.
4. Set
Set is an unordered collection of data. It is data structure that does not allows any
type of duplicate elements. Each element stored in set must be unique. This data
structure is also mutable.
8
4. Program
The given program is created for a furniture shop that buy and sells the furniture. In
the beginning of program, it shows the details of furniture shop and shows the items
available in the furniture shop. After that it displays the options to operate the program.
Press 1 for selling furniture, you can Press 2 for purchasing furniture and you can
Press 3 for exiting from program.
Firstly, If the user did input is 1 then the given program will start the selling the process
of furniture selling. After completing the selling process of the furniture, the program
will again ask the user to input their personal details like contact number full name and
their address. After entering the personal detail, the program will ask user to enter the
furniture id. After that program will displays name of the furniture of that furniture id
and ask use to input the number of quantities they want to sell. Then the program asks
the u whether they want to sell another furniture or not. If they say yes, the program
will ask laptop id and repeat the same process. Then the system will ask the user
whether they want to ship their product or not. After that the program will generates a
bill in the text file format and displays. Then it displays options to operate the system.
The user can choose option according to their need.
Secondly, All the process are same as selling process when user input is 2. The only
difference here is that user selected quantity of the item is added to the available
quantity in the store. Like the first one all the billing and detailed process are carried
out on the same way.
Lastly, If the user press 3 the program will stop and display the “Thank you” message
in the terminal.
9
Figure 6
Figure 7
10
Figure 8
Figure 9
4.1 Correctness
11
4.2 Implementation
Error in Python can be of two types i.e. Syntax errors and Exceptions. Errors are
problems in a program due to which the program will stop the execution. On the other
hand, exceptions are raised when some internal events occur which change the
normal flow of the program. (geeksforgeeks.org, 30/08/24) I have implemented try and
expect in this course work to manage any king of system failure.
My interface for this course work is terminal based or command line based. Every
operation in the system is carried out through command line. It is an user friendly
interface which makes user to use the system easily. Every sell and purchase process
can be carried out efficiently.
12
5. Testing
Test No 1
Expected Result: Invalid input message will display. System will again
ask to provide valid furniture id
Table 1
Figure 10
13
Test 2: Text File generation after selling and purchasing process
Test No 2
Table 2
Figure 11
14
Test 3: Checking try expecting implementation
Test No 3
Expected Result: Try and expect will work and system do not crash.
Table 3
Figure 12
15
Test 4: Quantity validation
Test No 4
Table 4
Figure 13
16
6. Conclusion
By, the help of this coursework I have got to know various components of python. I
have learned about data structure, function, file handling etc. From the report section
I learned about how to make a flow chat. I do face some problem while creating this
problem but by the help of my friend I have completed and succeeded. This course
work helps me to show my skill on python developing the program.
17
Reference
https://www.geeksforgeeks.org/introduction-to-python/
geeksforgeeks.org, 30/08/24. geeksforgeeks.org. [Online]
Available at: https://www.geeksforgeeks.org/python-exception-handling/
18
Appendix
Appendix of main.py
import read
import operations
import write
def furniture_shop():
print("\t\t\t\t Furniture Store Kathmandu")
print("\t\t\t\t\t NewRoad Kathmandu")
print("\t\t\t Contact: 9815475687 | 9867845921")
print("\n")
def user_interface():
print("Select an option as per your need.")
print("Press 1: For Sale.")
print("Press 2: For Purchase.")
print("Press 3: To Exit from System.\n")
def main():
furniture_shop()
read.display_items()
Run = True
while Run:
user_interface()
try:
user_input = int(input("Select an option to continue: "))
if user_input == 1:
loop = True
while loop:
sell = operations.furniture_selling()
write.user()
print("If you want to sell another furniture | Press 1")
print("If you dont want to sell another furniture | Press 2")
next_loop = True
while next_loop:
user_selection = int(input("Select an option: "))
if user_selection == 1:
next_loop = False
elif user_selection == 2:
loop = False
19
next_loop = False
receipt = write.selling_receipt(sell)
else:
print("Invalid Input. Provide a valid input thank you.")
elif user_input == 2:
main_loop = True
while main_loop:
purchase = operations.furniture_purchase()
write.user()
print("If you want to purchase another furniture | Press 1")
print("If you dont want to purchase another furniture | Press 2")
second_loop = True
while second_loop:
user_selection = int(input("Select an option: "))
if user_selection == 1:
main_loop = False
elif user_selection == 2:
main_loop = False
second_loop = False
purchase_receipt = write.purchase_receipt(purchase)
else:
print("Invalid Input. Provide a valid input thank you.")
elif user_input == 3:
print("Thank You for choosing us. ")
Run = False
else:
print("Invalid Option\n")
except ValueError:
print("Invalid Option Please Try Again\n")
main()
20
Operation:
import read
def furniture_selling():
selling_disc = []
furniture_disc = read.shop_items()
item_id_num = None
items = True
while items:
loop = True
while loop:
try:
item_id_num = int(input("Enter Furniture ID Number: "))
loop = False
except ValueError:
print("Invalid Input")
while item_id_num <= 0 or item_id_num > len(furniture_disc):
print("invalid Furniture ID Number \n")
item_id_num = int(input("Enter Furniture ID Number: "))
for i in furniture_disc.keys():
if i == item_id_num:
print("Furniture Name = ", furniture_disc[item_id_num][0], ", Product Name
= ", furniture_disc[item_id_num][1],
", Available Quantity = ", furniture_disc[item_id_num][2], ", Price = ",
furniture_disc[item_id_num][3])
items = False
item_quantity = furniture_disc[item_id_num][2]
quantity = int(input("Select required quantity= "))
while quantity <= 0 or quantity > int(item_quantity):
print("Not available quantity.\n")
quantity = int(input("Select required quantity= "))
manufacture_name = furniture_disc[item_id_num][0]
product_name = furniture_disc[item_id_num][1]
product_quantity = quantity
product_price = furniture_disc[item_id_num][3]
21
price = furniture_disc[item_id_num][3].replace("$", "")
total_amount = int(price) * int(product_quantity)
selling_disc.append([manufacture_name, product_name, product_quantity,
product_price, total_amount])
return selling_disc
def furniture_purchase():
purchase_disc = []
furniture_disc = read.shop_items()
item_id_num = None
items = True
while items:
loop = True
while loop:
try:
item_id_num = int(input("Enter Furniture ID Number: "))
loop = False
except ValueError:
print("Invalid Input")
while item_id_num <= 0 or item_id_num > len(furniture_disc):
print("invalid Furniture ID Number \n")
item_id_num = int(input("Enter Furniture ID Number: "))
for i in furniture_disc.keys():
if i == item_id_num:
print("Furniture Name = ", furniture_disc[item_id_num][0], ", Product Name
= ",
furniture_disc[item_id_num][1],
", Available Quantity = ", furniture_disc[item_id_num][2], ", Price = ",
furniture_disc[item_id_num][3])
items = False
item_quantity = furniture_disc[item_id_num][2]
quantity = int(input("Select required quantity= "))
furniture_disc[item_id_num][2] = int(furniture_disc[item_id_num][2]) +
int(quantity)
file = open("Furniture_Store.txt", "w")
for i in furniture_disc.values():
file.write(str(i[0]) + "," + str(i[1]) + "," + str(i[2]) + "," + str(i[3]))
file.write("\n")
file.close()
print("\n")
manufacture_name = furniture_disc[item_id_num][0]
product_name = furniture_disc[item_id_num][1]
product_quantity = quantity
22
product_price = furniture_disc[item_id_num][3]
price = furniture_disc[item_id_num][3].replace("$", "")
total_amount = int(price) * int(product_quantity)
purchase_disc.append([manufacture_name, product_name, product_quantity,
product_price, total_amount])
return purchase_disc
Read.py:
def shop_items():
shop_disc = {}
items_id = 1
file = open("Furniture_Store.txt", "r")
for i in file:
i = i.replace("\n","")
shop_disc.update({items_id: i.split(",")})
items_id += 1
file.close()
return shop_disc
def display_items():
print("======================================================")
print(" S.N Manufacturer Product Name Quantity Price")
print("======================================================")
file = open("Furniture_Store.txt", "r")
num = 1
for i in file:
print(" ", num, " " + i.replace(",", " "))
num += 1
file.close()
print("======================================================")
23
Write.py
def user():
global user_name, user_address, user_number
user_name = input("Enter your name: ")
user_address = input("Enter your address: ")
while True:
try:
user_number = int(input("Enter your contact number: "))
break
except ValueError:
print("Invalid Input\n")
def selling_receipt(furniture):
file = open(f"{user_name}.txt", "w")
file.write("Name = " + str(user_name) + "\n")
file.write("Address = " + str(user_address) + "\n")
file.write("Contact = " + str(user_number) + "\n")
num = 1
total_amount = 0
for sell in furniture:
total_amount += sell[4]
file.write("\nFurniture Number: " + str(num) + "\n")
file.write("Manufacture Name: " + sell[0] + "\n" + "Product Name: " + sell[1] +
"\n" + "Product Quantity: " + str(sell[2]) + "\n" + "Price: " + str(sell[3]) + "\n" + "Total
Amount: $" + str(sell[4]) + "\n")
print("\nFurniture Number: " + str(num))
print("Manufacture Name: " + sell[0] + "\n" + "Product Name: " + sell[1] + "\n" +
"Product Quantity: " + str(sell[2]) + "\n" + "Price: " + str(sell[3]) + "\n" + "Total Amount:
$" + str(sell[4]) + "\n")
file.write("\nTotal Amount: $" + str(total_amount) + "\n")
file.close()
def purchase_receipt(purchase):
file = open(f"{user_name}.txt", "w")
file.write("Name = " + str(user_name) + "\n")
file.write("Address = " + str(user_address) + "\n")
file.write("Contact = " + str(user_number) + "\n")
num = 1
total_amount = 0
for sell in purchase:
total_amount += sell[4]
file.write("\nFurniture Number: " + str(num) + "\n")
file.write(
"Manufacture Name: " + sell[0] + "\n" + "Product Name: " + sell[1] + "\n" +
24
"Product Quantity: " + str(
sell[2]) + "\n" + "Price: " + str(sell[3]) + "\n" + "Total Amount: $" + str(sell[4])
+ "\n")
print("\nFurniture Number: " + str(num))
print("Manufacture Name: " + sell[0] + "\n" + "Product Name: " + sell[1] + "\n" +
"Product Quantity: " + str(
sell[2]) + "\n" + "Price: " + str(sell[3]) + "\n" + "Total Amount: $" + str(sell[4]) +
"\n")
file.write("\nTotal Amount: $" + str(total_amount) + "\n")
file.close()
25
26