Professional Documents
Culture Documents
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 marks of zero will be awarded.
Table of Contents
1. Introduction: .............................................................................................................. 1
2. Discussion and Analysis .......................................................................................... 2
2.1 Algorithm: .............................................................................................................. 2
2.2 Flow Chart ............................................................................................................. 5
2.3 Pseudocode ......................................................................................................... 12
2.4 Data Structures .................................................................................................... 27
3. Program ................................................................................................................... 33
4. Testing: .................................................................................................................... 41
4.1. Test 1. ................................................................................................................. 41
4.2 Test 2. .................................................................................................................. 43
4.3 Test 3................................................................................................................... 44
4.4 Test 4................................................................................................................... 48
4.5 Test 5................................................................................................................... 52
4.5.1 Quantity reduction while renting costume ..................................................... 52
4.5.2 Quantity addition while returning costume .................................................... 55
5. Conclusion ............................................................................................................... 58
References ................................................................................................................... 59
Appendix ...................................................................................................................... 60
List of Figures
1. Introduction:
As part of our coursework, we were required to use the Python programming language to
create a Costume Rental System. To say we found the work challenging would be an
understatement. Not knowing the fundamentals of Python was enough to create a
functional system. Algorithms, pseudocodes, and flowcharts were to be used to explain
the software in great detail for the coursework that was due at the conclusion of week 12.
A costume rental application must be created with various options to rent the costume,
return the costume and display the bill or invoice after every transaction performed.
Since we had only begun our formal education in Python, finishing this report and the
coursework, which required us to create real software used in several stores and
locations, was a major accomplishment. Consequently, completing the required
education proved to be a challenging accomplishment. Many studies have been looked
at the curriculum in an effort to find solutions to these problems. In order to finish this
assignment by the deadline, the instructor was very helpful in making the necessary
changes required in order to meet every requirements of the coursework. Likewise,
various tools were used for the proper accomplishment of this coursework.
The following coursework might be a great help to any small level organization which are
related to renting the costumes or any other items. It can also be a great help to a single
individual as it is quiet easy and can be used by any user who have some knowledge
regarding the computer system. It helps to increase the quality of both the organization
and the individual.
1
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
2.1 Algorithm:
A Python algorithm is a set of commands that are executed to find a solution to a particular
problem. Algorithms are not language-specific and can be implemented in many
programming languages. There are no standard rules when writing algorithms. These
algorithms are resource and problem dependent, but share the same code structure as:
Flow control (if-else) and loops (do, while, for).
Some types of Algorithm are:
• Tree Traversal
• Sorting
• Searching and
• Graph Algorithms (upGrad, 2022).
2
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
3
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
Step 29: If the user provides valid Quantity i.e. more than 0, go to Step 31
Step 30: If the user provides invalid quantity show an invalid message, go to Step 28
Step 31: Update the Quantity by increasing in the dictionary, table and also in the text file
Step 32: Ask the user if they want to return more costume
Step 33: If yes, go to Step 24
Step 34: If no ask user to costumer details and also for how many days the costume was
returned.
Step 35: Display the invoice in the Shell and Generate a text file of invoice as the costumer
name
Step 36: Go to Step 3
Step 37: Stop
4
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
5
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
6
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
7
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
8
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
9
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
10
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
11
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
2.3 Pseudocode
Python pseudocode is more like an algorithmic representation of the code in discussion.
This means that when code is required, it cannot be written directly. Before being
formulated into actual code, the code must first be generated into Python pseudocode. A
Python pseudocode is defined as the process of creating an algorithmic representation
that looks like an English sentence. To put it simply, Python pseudocode is a code
representation that lacks syntax. As a result, there is no code in the Python pseudocode.
The algorithmic logic must be exactly replicated in Python pseudocode (EDUCBA, 2022).
12
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
13
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
14
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
15
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
16
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
17
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
18
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
IMPORT datetime
FROM functions IMPORT *
CALL FUNCTION welcome_to_program
DECLARE an empty list as cartRent
DECLARE an empty list as cartReturn
DECLARE a boolean variable as continueLoop and set its value to True
WHILE continueLoop is equals to True
CALL optionstoUsers FUNCTION
DECLARE a variable as usersOption which asks the users to enter the choice
IF usersOption is equals to rent
CALL messageForRent FUNCTION
CALL costumePrinting FUNCTION
ASSIGN FUNCTION validCostumeID with parameter mainElements to a variable
as ID
ASSIGN FUNCTION validQuantity with parameters mainElements,ID to a variable
as Quantity
APPEND ID and Quantity in cartRent list
ASSIGN FUNCTION stockreduction with parameters mainElements, ID, Quantity
to a variable as mainElements
ASSIGN FUNCTION priceofthecostumes with parameters mainElements, ID,
Quantity to a variable as totalAmount
CALL writeindictionary(mainElements) FUNCTION
DECLARE a boolean variable as secondContinueLoop and set its value to True
WHILE secondContinueLoop is equals to True
DISPLAY message as do the customer want to rent more costumes
CREATE a variable as userConfirmation which asks the customer whether
they want to rent another costume as well
19
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
20
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
21
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
22
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
23
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
Quantityreturn*fineDays*2 to it
DISPLAY Total Fine Amount as totalFine
ELSE
DISPLAY no any fine message
ASSIGN totalFine to str and to a variable totalFine1
OPEN file2 with Return_ and Nameofthecustomer in write
mode
WRITE in file2 RealMadrid Cloth Rental Store
WRITE in file2 Surunga, Jhapa
WRITE in file2 Customer Name as Nameofthecustomer
WRITE in file2 Customer Email Address as mail
WRITE in file2 Customer Contact Number as contactNo
WRITE in file2 Date and Time of Return as dateAndTime
WRITE in file2 Costume-ID,Name of costume,Costumes
Brand, Costumes Price, Quantity in appropriate format
FOR index in range of length of cartRent
DECLARE a variable as creturnID and SET value of
cartReturn[index][0] in int datatype to it
DECLARE a variable as creturnquantity and SET
value of cartReturn[index][0] in int datatype to it
DECLARE a variable as creturnName and SET value
of mainElements[creturnID][0] to it
DECLARE a variable as creturnBrand and SET value
of mainElements[creturnID][1] to it
DECLARE a variable as creturnPrice and SET value of
mainElements[creturnID][2], replace $ with nothing to it
DISPLAY index+1 and costume details in appropriate
format
END FOR
WRITE in file1 Total Fine Amount as totalFine1
CLOSE file1
25
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
26
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
• List:
Lists are storage structures for values of various data types. Lists keep the
information in the memory continuously. These are primarily utilized when frequent
access to the data is required, which indexing makes possible. Lists are mutable
which means it can be modified, added, or deleted once they’ve been created.
Example:
List=[1,2,3,”abc”]
print(List)
27
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
During the development of the program the built-in data structure List was also
used.
• Tuple:
A built-in data structure in Python called a tuple is a collection of ordered objects.
Tuples provide less functionality than lists do.
Mutability is the main factor that distinguishes tuples from lists. Tuples are
immutable, whereas lists can be changed. Once a tuple is formed, it cannot be
changed, added to, or removed.
Example:
Tuple= (‘Nischal’ , ’Khatiwada’)
print(Tuple)
• Set:
A set is described as an unusual combination of unusual pieces that do not occur
in a certain order. When an object's presence in a group of other items is more
significant than how frequently it occurs or how the objects are arranged, sets are
utilized. Sets can be changed, added to, replaced, or removed, unlike tuples, which
cannot (CFI, 2021).
Example:
Set= {1,2,3,”Hello”,”World”}
print(Set)
28
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
• Dictionary:
Dictionaries are Python's implementation of the associative array, a type of data
structure more commonly used in programming. An assortment of key-value pairs
makes up a dictionary. Every key-value pair links a key to its corresponding value.
Curly braces ({}) can be used to define a dictionary by enclosing a list of key-value
pairs separated by commas (Real Python, 2022).
Example:
Dictionary= {‘Name’: ‘Nischal’,’Ram’,’Shyam’}
print(Dictionary)
During the development of the program the built-in data structure List was also
used.
• Stack
• Queue
• Tree
• Linked List
• HashMap
29
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
3. Primitive Datatypes
• Integer:
Integers refers to the positive or negative whole number that are without decimal
or fraction. Python has no limit on the length of an integer. It can have any length
such as integers 10,11,15,7,-1 etc. The value of integer datatype is represented
by int class.
During the development of the program many integer datatypes were used in order
to store the integer values provided by the user.
In the above figure Quantity is the integer data-type which is used to store the
quantity provided by the user.
30
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
• Float:
Float refers to the real numbers or irrational numbers which contains the floating
points representation such as 1.11, 100.2, 7.77 etc. Classification of float is done
by decimal point. Float is accurate upto 15 decimal points. The value of float
datatype is represented by float class
During the development of the program I have used float datatype to change the
value of price previously stored in string datatype to float.
• String:
String refers to the collection of sequence of characters which are set in a single
quote, double-quote or triple quote such as “Welcome to the program”, ‘Hello
world’ etc. The value of String datatype is represented by str class.
During the development of the program I have used many String datatypes in order
to store the Character values or string values provided by the user such as Name
of the customer, E-mail, phone number etc
31
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
• Boolean:
Boolean datatype is a built-in data type in python which can only have two values
either True or False. Booleans enable the creation of logical conditions that define
an application’s behaviour. Representing the truth values of an expressions is the
main function of a Boolean.
Example:
a=100
b=101
print(a==b)
The program returns the value False as 100 and 101 are not equal.
During the development of the program I have used some of the Boolean variables.
32
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
3. Program
Description of Program:
As the program is started, firstly it shows the Welcome message as Welcome to costume
rental application. The desirable option is provided to the costumer whether to rent, return
or exit.
When the costumer provides an invalid input such as -1 or any other values except rent,
return and exit an invalid message appears in the Shell.
33
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
Rent Process
When the costumer inputs rent, a table which contains the details of the costumes like
costume id, Name of costume, Costumes Brand, Costumes Price and Quantity appears
in the Shell.
There are seven costumes that are available in our costume rental store. Each costume
contains a different amount of Quantity and Price. Different ID is assigned to a particular
costume.
Then the program asks the user to input the ID of the costume that they want to rent. If
the user inputs ID less than 1 and more than 7 an invalid message appears in the IDLE
Shell because there are only seven different costumes available in the store.
When the user provides a valid costume id i.e. within the range of 1 to 7, a message
saying whether the costume with the provided ID is available in the store or not.
34
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
The user inputs the ID of the costume as 1 and provides the quantity as 10 the table
appears in the Shell were the Quantity of Cop Costume is decreased from 40 units to 20
units. The price of the particular costume is also displayed in the screen.
Now the program asks the user whether he/ she wants to rent more costume or not. The
user needs to input Yes if he/she wants to rent more else he/she needs to input no.
If the user inputs Yes the program asks the user the id and quantity of the costume and
the table with decreased quantity again appears in the IDLE Shell.
35
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
The program again asks the user do they want to rent more costume or not. When the
costumer inputs no the costumer need to enter the name, email and contact number.
After that an Invoice in the Shell is created and a new Text file with the same name the
costumer just entered is generated. The text file contains all the details of the transaction
and the Grand Total Amount.
In the above invoice which is generated in the new text file, the name is same as the
name which is provided by the customer in the above program.
36
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
Return Process
When the costumer inputs return, a table which contains the details of the costumes like
costume id, Name of costume, Costumes Brand, Costumes Price and Quantity appears
in the Shell.
There are seven costumes that are available in our costume rental store. Each costume
contains a different amount of Quantity and Price. Different ID is assigned to a particular
costume.
Then the program asks the user to input the ID of the costume that they want to return. If
the user inputs ID less than 1 and more than 7 an invalid message appears in the IDLE
Shell because there are only seven different costumes available in the store.
37
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
When the user provides a valid costume id i.e. within the range of 1 to 7, a message
saying whether the costume with the provided ID is available in the store or not.
The user inputs the ID of the costume as 2 and provides the quantity as 6 the table
appears in the Shell were the Quantity of Formal Suite is increased from 20 units to 26
units. The price of the particular costume is also displayed in the screen.
Now the program asks the user whether he/ she wants to return more costume or not.
The user needs to input Yes if he/she wants to return more else he/she needs to input
no.
If the user inputs Yes the program asks the user the id and quantity of the costume and
the table with increased quantity again appears in the IDLE Shell.
38
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
The program again asks the user do they want to return more costume or not. When the
costumer inputs no the costumer need to enter the name, email and contact number.
After that an Invoice in the Shell is created and a new Text file with the same name the
costumer just entered is generated. The user also needs to enter for how many days the
costume was rented. If the costume is rented for more than 5 days fine of $2 per day is
assigned. The text file contains all the details of the transaction and the Grand Total
Amount.
39
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
In the above invoice which is generated in the new text file, the name is same as the
name which is provided by the customer in the above program.
Exit Program
When the program asks the user whether to rent, return or exit. If you enter exit the
program shows a message as Thank You for choosing and using our application and the
program terminates.
40
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
4. Testing:
4.1. Test 1.
• While the program asks to enter the ID of the costume enter the String
value or any other values.
• Press Enter
41
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
42
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
4.2 Test 2.
Providing negative and non-existed value as input.
Test Number 2
Objective To provide negative and non-existed value as input.
Action • Open the IDLE Shell
• While the program asks to select the choice rent, return or exit.
Expected A message saying, “Invalid Input!!!!, Please select the value as per the
Result provided options.” appears.
Actual Result A message saying, “Invalid Input!!!!, Please select the value as per the
provided options.” appears.
Conclusion The testing was Successful
43
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
4.3 Test 3
Test Number 3
Objective To show the file generation of renting costume.
Action • Open the IDLE Shell
• While the program asks to select the choice rent, return or exit.
• Enter rent.
• Enter the id and quantity of the costume for rent and when the
program asks if the user wants to rent another costume as well
enter ‘Yes’.
• Again, the program asks the user to input the id and quantity of
the costume.
• Enter the id and quantity and when asked for user if you want to
rent another costume as well enter ‘No’.
• The invoice for rent will be printed in the shell and a text file will
be generated with every details.
44
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
45
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
46
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
47
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
4.4 Test 4
Test Number 4
Objective To show the file generation of returning costume.
Action • Open the IDLE Shell
• While the program asks to select the choice rent, return or exit.
• Enter return.
• Enter the id and quantity of the costume for return and when the
program asks if the user wants to return another costume as well
enter ‘Yes’.
• Again, the program asks the user to input the id and quantity of
the costume.
• Enter the id and quantity and when asked for user if you want to
return another costume as well enter ‘No’.
• The invoice for return will be printed in the shell and a text file will
be generated with every details.
48
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
49
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
50
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
51
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
4.5 Test 5
Update in Stock of costume
• While the program asks to select the choice rent, return or exit.
• Enter rent
52
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
53
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
54
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
• While the program asks to select the choice rent, return or exit.
• Enter return
55
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
56
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
57
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
5. Conclusion
The coursework is mainly about a Costume rental application which can be used to rent
and return the costumes. This coursework can be viewed as a sample of a program which
provides the knowledge on how the store functions. This was the first time I had used
Python programming language. I did not feel comfortable or confident doing the
coursework in the beginning but as I started diving deep into it I had a better
understanding about the coursework with numerous amounts of research and advices
from the teachers. We had just begun understanding into Python's fundamentals when
the coursework was handed over to us. As a result, we struggled greatly to do our work.
After a great deal of research, reading several books and websites, and putting in many
hours of work, I was able to finish the task. Any time I ran into difficulty completing a
mission, I immediately contacted the module leaders and the elders who had good
knowledge about the coursework. With the support of my Lecturer, tutors, and seniors, I
was able to finish the code and the report. While working on my project, I studied a
number of books, journals, and other materials to improve my understanding of Python
and to boost my growing interest towards the language. This project helped me grow in
many ways, and I learned a ton that will serve me well in my future programming journey.
Completing the assignments was great fun, even though it required a lot of hard work and
pressure.
I came into this course with a basic understanding of Python, but now I have a much
deeper understanding thanks to this program. I have learned my way around the library
and feel comfortable using its resources. Having read this book, I feel like I have a much
better grasp of information systems, operations, and iteration. I finally got the hang of
using Python loops. I have a much better grasp of how text files are used in Python today.
My Python knowledge has actually grown substantially. To add, I'm having more fun
learning Python.
58
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
References
CFI, 2021. Python Data Structures. [Online]
Available at: https://corporatefinanceinstitute.com/resources/knowledge/other/python-
data-structures/
EDUCBA, 2022. Complete Guide to Python Pseudocode. [Online]
Available at: https://www.educba.com/python-pseudocode/
GeeksforGeeks, 2022. An introduction to Flowcharts. [Online]
Available at: https://www.geeksforgeeks.org/an-introduction-to-flowcharts/
GeeksforGeeks, 2022. Python Data Structures. [Online]
Available at: https://www.geeksforgeeks.org/python-data-structures/
Real Python, 2022. Dictionaries in Python. [Online]
Available at: https://realpython.com/python-dicts/
upGrad, 2022. Data Structures & Algorithm in Python. [Online]
Available at: https://www.upgrad.com/blog/data-structures-algorithm-in-python/
59
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
Appendix
print("====================================================\n\tWelcome
to costume rental
application\n====================================================")
print("\n")
# defining a function which provides option to the user such as rent, return or exit
def optionsToUsers():
print("Select a desirable option.\n(Rent) || Enter rent for renting a costume.\n(Return)
|| Enter return for returning a costume.\n(Exit) || Enter exit to exit. ")
# defining a function which extracts the items from the costume text file
def fileDataExtraction():
file=open("costume.txt","r") # opens the costume.txt file in read mode
elements=file.readlines() # gets the access of every line in the text file
file.close() # closes the text file
return elements
# defining a function which creates a dictionary and passes all the elements from the
costume text file
def get_dictionary(fileDataExtraction):
60
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
dictionary={}
for index in range(len(fileDataExtraction)):
dictionary[index+1]=fileDataExtraction[index].replace("\n","").split(",") # assigning
the key and value to the dictionary by replacing \n with nothing and spliting by ,
return dictionary
# defining a function to write the details of items from the costume.txt file in the form of
table
def costumePrinting():
print("--------------------------------------------------------------------------------------------------------
")
print("Costume-Id","\t","Name of costume","\t","Costumes Brand","\t","Costumes
Price","\t","Quantity")
print("--------------------------------------------------------------------------------------------------------
")
for key,value in mainElements.items():
print(key,"\t\t",value[0],"\t\t",value[1],"\t\t",value[2],"\t\t\t",value[3])
# defining a function which takes a valid costume ID from the user to rent
def validCostumeID(mainElements):
validInput=False
while validInput==False:
exception=False
while exception==False:
try:
ID=int(input("Enter the id of the costume you want to rent: "))
for0=int(mainElements[ID][3])
print("\n")
exception=True
except:
forException()
if for0 <=0:
print("-------------------------------")
print("The Costume is not available.")
print("-------------------------------")
ID=int(input("\nEnter the id of the costume you want to rent: "))
else:
print("-------------------------------------------------------\n The Costume with the id you
provided is available in the store\n-------------------------------------------------------\n")
61
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
print("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
print("There is no any costume with the ID you just entered.\n Please enter the
valid costume ID")
print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n")
# defining a function which takes valid quantity of the costume from the customer to rent
def validQuantity(mainElements,ID):
exception=False
while exception==False:
try:
Quantity=int(input("Enter the quantity of the costume: \n"))
exception=True
except:
forException()
while Quantity <= 0 or Quantity > int(mainElements[ID][3]):
if Quantity <= 0:
print("Enter the valid amount of quantity you want to rent.\n")
else:
print("\n--------------------------------------------------------\n The quantity provided is
more then the stock available.\n--------------------------------------------------------\n")
return Quantity
# defining a function which reduces the quantity of the costume when it is rented
def stockreduction(mainElements,ID,Quantity):
mainElements[ID][3]=str(int(mainElements[ID][3])- Quantity)
costumePrinting()
print("")
return mainElements
# defining a function which writes the deduced or added quantites in the costume text
file
def writeindictionary(dictionary):
file=open("costume.txt","w")
for i in dictionary.values():
line=str(i[0]+","+ i[1]+","+i[2]+","+i[3])
62
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
file.write(line)
file.write("\n")
file.close
# defining a function which takes a valid costume ID from the user to rent
def validCostumeIDReturn(mainElements):
validInput=False
while validInput==False:
exception=False
while exception==False:
try:
IDreturn=int(input("Enter the id of the costume you want to return: "))
print("\n")
exception=True
except:
forException()
if(IDreturn>=1 and IDreturn<=len(mainElements)):
validInput=True
print("------------------------------------------------------------\n The Costume with the
following id is available in the store and you can returnit..\n---------------------------------------
---------------------\n")
return IDreturn
else:
print("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
print("There is no any costume with the ID you just entered.\n Please enter the
valid costume ID")
print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n")
# defining a function which takes price of the costume from the text file by replacing $
63
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
# defining a function which takes valid quantity of the costume from the customer to rent
def validQuantityReturn(mainElements,ID):
exception=False
while exception==False:
try:
Quantityreturn=int(input("Enter the quantity of the costume you want to return:
\n"))
exception=True
except:
forException()
return Quantityreturn
# defining a function which adds the quantity of the costume when it is returned
def stockaddition(mainElements,ID,Quantity):
mainElements[ID][3]=str(int(mainElements[ID][3])+ Quantity)
costumePrinting()
print("")
return mainElements
64
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
welcome_to_program()
cartRent=[] # declearing an empty list to append the costume details for rent
cartReturn=[] # declaring an empty list to append the costume details for return
continueLoop=True
while continueLoop==True:
optionsToUsers()
usersOption=input("Enter your choice: ").lower()
if usersOption=="rent":
messageForRent()
costumePrinting()
print("------------------------------------------------------------------------------------------------------
--\n")
ID=validCostumeID(mainElements)
Quantity=validQuantity(mainElements,ID)
cartRent.append([ID,Quantity])
mainElements=stockreduction(mainElements,ID,Quantity)
print("------------------------------------------------------------------------------------------------------
--\n")
totalPrice=priceofthecostumes(mainElements, ID, Quantity)
writeindictionary(mainElements)
secondContinueLoop=True
while secondContinueLoop==True:
print("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++")
print("Do the customer want to rent another costume as well???")
userConfirmation=input("Please enter 'yes' if the customer want to rent else
enter 'no': ").lower()
print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++")
print("\n")
if userConfirmation == "yes":
messageForRent()
costumePrinting()
print("-----------------------------------------------------------------------------------------------
---------\n")
ID=validCostumeID(mainElements)
Quantity=validQuantity(mainElements,ID)
cartRent.append([ID,Quantity])
65
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
mainElements=stockreduction(mainElements,ID,Quantity)
print("-----------------------------------------------------------------------------------------------
---------\n")
totalPrice=priceofthecostumes(mainElements, ID, Quantity) + totalPrice
writeindictionary(mainElements)
elif userConfirmation=="no":
Nameofthecustomer= nameofcustomer()
mail=email()
contactNo=phone()
print("\n-----------------------------")
print("\t Invoice details\n-----------------------------\n")
print("Customer Name: "+ Nameofthecustomer)
print("Customer Email Address: "+ mail)
print("Customer Contact Number : "+ contactNo)
dateAndTime = str(datetime.datetime.now().replace(microsecond=0))
print("Costume Rented Date: "+ dateAndTime)
print("\nRented costumes with Brand: ")
# using loop to get access to every elements in the cartRent
for index in range(len(cartRent)):
costumeID=int(cartRent[index][0])
costumequantity=int(cartRent[index][1])
costumeName=mainElements[costumeID][0]
costumeBrand=mainElements[costumeID][1]
costumePrice=mainElements[costumeID][2].replace("$","")
particularPrice=int(costumePrice)*costumequantity
print((index+1),". "+costumeName+","+costumeBrand+": |The total amount
for "+costumeName+" is $: "+str(particularPrice)+"|")
print()
print("***********************")
print("Grand Total: ", totalPrice) # displaying the Grand Total
print("***********************")
totalPrice1=str(totalPrice)
file1=open("Rent_ "+Nameofthecustomer+".txt","w")
file1.write("\t\t\tRealMadrid Cloth Rental Store\n")
file1.write("\t\t\t\tSurunga, Jhapa\n")
file1.write("\n")
file1.write("Customer Name: "+ Nameofthecustomer+"\n")
file1.write("Customer Email Address: "+ mail+"\n")
file1.write("Customer Contact Number: "+ contactNo+"\n")
dateAndTime = str(datetime.datetime.now().replace(microsecond=0))
file1.write("The Date and Time of Borrow: "+ dateAndTime+"\n")
file1.write("\n--------------------------------------------------------------------------------------
--\n")
66
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
file1.write(str(index+1)+"\t\t"+costumeName+"\t\t"+costumeBrand+"\t\t"+costumePrice+"
\t\t\t"+str(costumequantity)+"\t\t"+str(particularPrice)+"\n")
file1.write("\nGrand Total: $"+ totalPrice1+"\n")
file1.close()
print("\n")
secondContinueLoop=False
else:
print("Please provide the value either true or false only!!!")
elif usersOption=="return":
messageForReturn()
costumePrinting()
print("------------------------------------------------------------------------------------------------------
--\n")
IDreturn=validCostumeIDReturn(mainElements)
Quantityreturn=validQuantityReturn(mainElements,IDreturn)
cartReturn.append([IDreturn,Quantityreturn])
mainElements=stockaddition(mainElements,IDreturn,Quantityreturn)
print("------------------------------------------------------------------------------------------------------
--\n")
writeindictionary(mainElements)
continueloop=True
while continueloop==True:
print("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++")
print("Do the customer want to rent another costume as well???")
userConfirmation=input("Please enter 'yes' if the customer want to rent else
enter 'no': ").lower()
print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++")
print("\n")
67
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
if userConfirmation == "yes":
messageForReturn()
costumePrinting()
print("-----------------------------------------------------------------------------------------------
---------\n")
IDreturn=validCostumeIDReturn(mainElements)
Quantityreturn=validQuantityReturn(mainElements,IDreturn)
cartReturn.append([IDreturn,Quantityreturn])
mainElements=stockaddition(mainElements,IDreturn,Quantityreturn)
print("-----------------------------------------------------------------------------------------------
---------\n")
writeindictionary(mainElements)
elif userConfirmation=="no":
Nameofthecustomer= nameofcustomer()
mail=email()
contactNo=phone()
days = int(input("Enter the Number of Days the costume was rented: "))
print("\n-----------------------------")
print("\t Invoice details\n-----------------------------\n")
print("Customer Name: "+ Nameofthecustomer)
print("Customer Email Address: "+ mail)
print("Customer Contact Number: "+ contactNo)
dateAndTime = str(datetime.datetime.now().replace(microsecond=0))
print("Costumer Return Time: "+ dateAndTime)
print("\nRetruned costumes with Brand: ")
# using loop to get access to every elements in the cartRent
for index in range(len(cartReturn)):
creturnId=int(cartReturn[index][0])
creturnquantity=int(cartReturn[index][1])
creturnName=mainElements[creturnId][0]
creturnBrand=mainElements[creturnId][1]
print((index+1),". "+creturnName+","+creturnBrand)
totalFine=0
if days>5:
fineDays=days-5
totalFine=Quantityreturn*fineDays*2
print("\nTotal Fine Amount: ",totalFine)
else:
print("\nSince you have returned all the costumes within 5 days. You don't
have to pay any fine amount.")
totalFine1=str(totalFine)
file2=open("Return_ "+Nameofthecustomer+".txt","w")
file2.write("\t\t\tRealMadrid Cloth Rental Store\n")
file2.write("\t\t\t\tSurunga, Jhapa\n")
68
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
file2.write("\n")
file2.write("Customer Name: "+ Nameofthecustomer+"\n")
file2.write("Customer Email Address: "+ mail+"\n")
file2.write("Customer Contact Number: "+ contactNo+"\n")
dateAndTime = str(datetime.datetime.now().replace(microsecond=0))
file2.write("The Date and Time of Return: "+ dateAndTime+"\n")
file2.write("\n---------------------------------------------------------------------------\n")
file2.write("Costume-Id\tName of costume\tCostumes Brand\tCostumes
Price\tQuantity\n")
file2.write("---------------------------------------------------------------------------\n")
# using loop to get access to every elements in the cartRent
for index in range(len(cartReturn)):
creturnId=int(cartReturn[index][0])
creturnquantity=int(cartReturn[index][1])
creturnName=mainElements[creturnId][0]
creturnBrand=mainElements[creturnId][1]
creturnPrice=mainElements[creturnId][2].replace("$","")
file2.write(str(index+1)+"\t\t"+creturnName+"\t\t"+creturnBrand+"\t\t"+creturnPrice+"\t\t"+
str(creturnquantity)+"\n")
file2.write("\nTotal Fine Amount: $"+totalFine1)
file2.close()
print("\n")
continueloop=False
else:
print("Please provide the value either true or false only!!!")
69
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING
70
NISCHAL KHATIWADA