You are on page 1of 74

Module Code & Module Title

CS4051NI Fundamentals of Computing

Assessment Weightage & Type


60% Individual Coursework

Year and Semester


2021-22 Summer

Student Name: Nischal Khatiwada


Group: C6
London Met ID: 21049542
College ID: np01cp4a210198
Assignment Due Date: 26th August, 2022
Assignment Submission Date: 26th August, 2022

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

Figure 1: First screenshot of flowchart ............................................................................ 6


Figure 2: Second screenshot of flowchart ....................................................................... 7
Figure 3: Third Screenshot of flowchart........................................................................... 8
Figure 4: Fourth screenshot of flow chart ........................................................................ 9
Figure 5: Fifth screenshot of flowchart .......................................................................... 10
Figure 6: Last screenshot of the flowchart ..................................................................... 11
Figure 7: Data Structures in Python .............................................................................. 27
Figure 8: List data structure used in the program .......................................................... 28
Figure 9: Dictionary data structure used in the program................................................ 29
Figure 10: Screenshot of the Integer data-type ............................................................. 30
Figure 11: Screenshot of the float datatype ................................................................... 31
Figure 12: Screenshot of the String datatype ................................................................ 31
Figure 13: Screenshot of the boolean variable .............................................................. 32
Figure 14: Implementation of Try and Except in code ................................................... 41
Figure 15: Try and Except in IDLE Shell ....................................................................... 42
Figure 16: Screenshot when valid ID is entered. ........................................................... 42
Figure 17:Screenshot of providing negative and non-existed value as input................. 43
Figure 18: Screenshot of Multiple costume rent ............................................................ 46
Figure 19: Screenshot of rent invoice in shell ................................................................ 46
Figure 20: Generation of text file and rent invoice printing ............................................ 47
Figure 21: Screenshot of Multiple costume return ......................................................... 50
Figure 22:Screenshot of return invoice in shell ............................................................. 50
Figure 23: Generation of text file and return invoice printing ......................................... 51
Figure 24: Costume text file before stock reduction. ..................................................... 52
Figure 25: Full costume renting process ....................................................................... 53
Figure 26: Quantity reduction in costume text file ......................................................... 54
Figure 27: Costume text file before stock addition ........................................................ 55
Figure 28: Full costume returning process .................................................................... 56
Figure 29: Quantity addition in costume text file ............................................................ 57
List of Tables

Table 1: Basic shapes used in flowchart ......................................................................... 5


Table 2: Implementation of Try and Except ................................................................... 41
Table 3: Providing negative and non-existed value as input. ........................................ 43
Table 4: File generation of renting costume .................................................................. 44
Table 5: File generation of renting costume .................................................................. 48
Table 6: Stock reduction while renting costume. ........................................................... 52
Table 7: Stock addition while returning costume ........................................................... 55
CS4051NI FUNDAMENTALS OF COMPUTING

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.

Some of the goals and the objectives of the project are:


• To create a user-friendly software using a programming language i.e. Python
which can be used in a costume rental store.
• To rent and return the costumes as per the instructions of the user.
• To successfully generate which contains the costumer details, costumers rented
or returned, date and time etc.

1
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

2. Discussion and Analysis

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

Algorithm for the program:


Step 1: START
Step 2: Display welcome to the rental store application message
Step 3: Display options for the user such as Enter rent for renting, Enter return for
returning and Enter exit to exit from the program
Step 4: If the user input is rent, go to Step 11
Step 6: If the user input is return, go to Step
Step 8: If the user input is exit, display an appropriate exit message and terminate the
program
Step 10: Extract every data from the costume text file and store it in the form of dictionary
Step 11: Display appropriate message for rent
Step 12: Display all the details of the costumes in table format
Step 13: Ask the user to enter the ID of the costume to rent
Step 14: If the user provides a valid costume ID, go to Step 16
Step 15: else display an appropriate invalid ID message and go to Step 13
Step 16: Ask the user to enter the Quantity of the costume
Step 17: If the Quantity of the costume is available in the store is 0 then go to Step 13
Step 18: If the user provides the Quantity which is more than the stock available then
show an appropriate message
Step19: If the user provides the valid Quantity
Step 20: Update the Quantity by decreasing in the dictionary, table and also in the text
file.
Step 21: Ask the user if they want to rent more costume
Step 22: If yes, go to step 12
Step 23: If no ask user to input name, email and contact number and display the invoice
in the Shell and Generate a text file of invoice as the costumer name
Step 24: Display all the details of the costumes in the table format to return
Step 25: Ask the user to enter the ID of the costume to return
Step 26: If the user provides valid costume ID, go to step 27
Step 27: If the user provides invalid costume ID display invalid message, go to step 25
Step 28: Ask the costumer to enter the Quantity to return

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

2.2 Flow Chart

A flowchart is a graphical representation of an algorithm. Programmers frequently use it


as a program-planning tool to solve problems. It makes use of linked symbols to represent
the flow of information and processing. The process of creating a flowchart for an
algorithm is referred to as "flowcharting” (GeeksforGeeks, 2022).

Basic shapes used in a flowchart are:

Name Shapes Functions

1.Oval An oval represents a start or end


point.

2. Arrows A line is a connector that shows


relationships between the
representative shapes.

3. Parallelogram A parallelogram represents input


or output.

4. Rectangle A rectangle represents a


process.

5. Diamond A diamond indicates a decision.

Table 1: Basic shapes used in flowchart

5
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

Figure 1: First screenshot of flowchart

6
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

Figure 2: Second screenshot of flowchart

7
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

Figure 3: Third Screenshot of flowchart

8
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

Figure 4: Fourth screenshot of flow chart

9
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

Figure 5: Fifth screenshot of flowchart

10
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

Figure 6: Last screenshot of the flowchart

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).

The pseudo code for the program is below:

DEFINE FUNCTION welcome_to_program()


DISPLAY Welcome to costume rental application

DEFINE FUNCTION optionsToUsers()


DISPLAY Select a desirable option.
(Rent) Enter rent for renting a costume.
(Return) Enter return for returning a costume.
(Exit) Enter exit to exit

DEFINE FUNCTION messageForRent()


DISPLAY Welcome for renting the costume

DEFINE FUNCTION messageForReturn()


DISPLAY Welcome for returning the costume!! Click on the provided options to
return the costume you have borrowed.

12
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

DEFINE FUNCTION messageForExit()


DISPLAY Thank You for choosing and using our application.

DEFINE FUNCTION fileDataExtraction()


OPEN file costume.txt in read mode
ASSIGN file.readlines FUNCTION to variable as elements
CALL file.close FUNCTION
RETURN elements

DEFINE FUNCTION get_dictionary(fileDataExtraction)


DECLARE an empty dictionary as dictionary
FOR index in range of length of fileDataExtraction
dictionary[index+1] equals to index of fileDataExtraction and replace “\n”
with “” and split with “\n”
RETURN dictionary
END FOR

DECLARE a global variable as contentsInFile and assign FUNCTION fileDataExtraction


DECLARE a global variable as mainElements and assign DEFINE get_dictionary with
parameter contentsInFIle

DEFINE FUNCTION costumePrinting()


DISPLAY Costume-Id, Name of costume, Costumes Brand, Costumes Price,
Quantity with appropriate format
FOR key, value in mainElements.items()
DISPLAY key, 0 index of value, 1 index of value, 2 index of value, 3 index
of value with appropriate format
END FOR

13
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

DEFINE FUNCTION validCostumeID(mainElements)


DECLARE a boolean variable as validInput and set its value to False
WHILE validInput equals to False
DECLARE a boolean variable as exception and set its value to False
WHILE exception equals to False
TRY
DECLARE a variable as ID which takes input as id of the
costume from user
DECLARE a variable as for0 which takes the Quantity of the
costume from text file and sets to integer datatype
UPDATE exception to True
EXCEPT
CALL forException FUNCTION
IF for0 is less and equals to 0
DISPLAY The costume is not available
DECLARE a variable as ID which takes input as id of the costume
from user
ELSE
DISPLAY The costume with the id you provided is available in the
store

IF ID is more and equals to 1 and ID is less and equals to len(mainElements)


UPDATE validInput to True
RETURN ID
ELSE
DISPLAY There is no any costume with the ID you just entered
Please enter the valid costume

14
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

DEFINE FUNCTION validQuantity(mainElements,ID)


DECLARE a boolean variable as exception and set its value to False
WHILE exception equals to False
TRY
CREATE a variable as Quantity which takes the quantity of the
costume and sets to int
UPDATE exception to True
EXCEPT
CALL forException FUNCTION
WHILE Quantity is less and equals to 0 OR Quantity is more than
int(mainElements[ID][3])
IF Quantity is less and equals to 0
DISPLAY Enter the valid amount of quantity
ELSE
DISPLAY the quantity provided is more then the stock available
DECLARE a variable as Quantity which takes the quantity of the costume
and set to int
RETURN Quantity

DEFINE FUNCTION stockreduction(mainElements, ID, Quantity)


SET mainElements[ID][3]- Quantity to mainElements[ID][3]
CALL costumePrinting FUNCTION
RETURN mainElements

DEFINE FUNCTION writeindictionary(dictionary)


OPEN file costume.txt in write mode
FOR I in dictionary.values()
DECLARE a variable as line and ASSIGN 0 index of i, 1 index of i, 2 index
of i, 3 index of i

15
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

WRITE in file with parameter line


END FOR
CLOSE file

DEFINE FUNCTION nameofcustomer()


DECLARE a variable as usersName which asks the costumer to enter the name
RETURN usersName

DEFINE FUNCTION email()


DECLARE a variable as mail which asks the costumer to enter the email
RETURN mail

DEFINE FUNCTION phone()


DECLARE a variable as contact which asks the costumer to enter the contact no
RETURN contact

DEFINE FUNCTION validCostumeIDReturn(mainElements)


DECLARE a boolean variable as validInput and set its value to False
WHILE validInput equals to False
DECLARE a boolean variable as exception and set its value to False
WHILE exception equals to False
TRY
DECLARE a variable as IDreturn which takes input as id of
the costume from user
UPDATE exception to True
EXCEPT
CALL forException FUNCTION

16
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

IF ID is more and equals to 1 and ID is less and equals to len(mainElements)


UPDATE validInput to True
DISPLAY The costume is availabe
RETURN IDreturn
ELSE
DISPLAY There is no any costume with the ID you just entered

DEFINE FUNCTION priceofthecostumes(mainElements, ID, Quantity)


ASSIGN mainElements[ID][2] with replacement of $ to none to a variable price
DISPLAY renting price for a single costume as price
ASSIGN price in float variable multiplied by Quantity to a variable
priceofancostume
RETURN priceofancostume

DEFINE FUNCTION validQuantityReturn(mainElements,ID)


DECLARE a boolean variable as exception and set its value to False
WHILE exception equals to False
TRY
DECLARE a variable as Quantityreturn which takes the quantity of
the costume and sets to int
UPDATE exception to True
EXCEPT
CALL forException FUNCTION
RETURN Quantityreturn

17
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

DEFINE FUNCTION stockraddition(mainElements, ID, Quantity)


SET mainElements[ID][3]+ Quantity to mainElements[ID][3]
CALL costumePrinting FUNCTION
RETURN mainElements

DEFINE FUNCTION forException


DISPLAY Please enter valid input!!!!

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

IF userConfirmation equals to yes


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
ADD 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 + totalAmount to a variable as
totalAmount
CALL writeindictionary(mainElements) FUNCTION
ELIF userConfirmation equals to no
ASSIGN nameofcustomer FUNCTION to a variable as
Namefothecustomer
ASSIGN email FUNCTION to a variable as mail
ASSIGN phone FUNCTION to a variable as contactNo
DISPLAY Invoice Details
DISPLAY Customer Name as Nameofthecustomer
DISPLAY Customer Email Address as mail
DISPLAY Customer Contact Number as contactNo
DISPLAY Costume Rented Date as dateAndTime
DISPLAY Rented costumes with Brand
FOR index in range of length of cartRent
DECLARE a variable as costumeID and SET value of
cartRent[index][0] in int datatype to it
DECLARE a variable as costumequantity and SET value of
cartRent[index][0] in int datatype to it

20
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

DECLARE a variable as costumeName and SET value of


mainElements[costumeID][0] to it
DECLARE a variable as costumeBrand and SET value of
mainElements[costumeID][1] to it
DECLARE a variable as costumeName and SET value of
mainElements[costumeID][2], replace $ with nothing to it
DECLARE a variable as particularPrice and SET value of
costumePrice in int datatype * costumequantity to it
DISPLAY index+1, costumeName, costumeBrand and the
total amount for costumeName is as particularPrice with string
datatype in appropriate format
DISPLAY Grand Total as totalPrice

ASSIGN totalPrice to str and to a variable totalPrice1


OPEN file1 with Rent_ and Nameofthecustomer in write mode
WRITE in file1 RealMadrid Cloth Rental Store
WRITE in file1 Surunga, Jhapa
WRITE in file1 Customer Name as Nameofthecustomer
WRITE in file1 Customer Email Address as mail
WRITE in file1 Customer Contact Number as contactNo
WRITE in file1 Date and Time of Borrow as dateAndTime
WRITE in file1 Costume-ID, Name of costume, Costumes Brand,
Costumes Price, Quantity, Total Price in appropriate format
FOR index in range of length of cartRent
DECLARE a variable as costumeID and SET value of
cartRent[index][0] in int datatype to it
DECLARE a variable as costumequantity and SET value of
cartRent[index][0] in int datatype to it
DECLARE a variable as costumeName and SET value of
mainElements[costumeID][0] to it
DECLARE a variable as costumeBrand and SET value of
mainElements[costumeID][1] to it

21
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

DECLARE a variable as costumeName and SET value of


mainElements[costumeID][2], replace $ with nothing to it
DECLARE a variable as particularPrice and SET value of
costumePrice in int datatype * costumequantity to it
WRITE in file1 index+1, costumeName, costumeBrand and
the total amount for costumeName is as particularPrice with
string datatype in appropriate format
END FOR
WRITE in file1 Grand Total as totalAmount
CLOSE file1
UPDATE secondContinueLoop to False
ELSE
DISPLAY please provide the value either true or false

22
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

ELIF usersOption equals to return


CALL messageForReturn FUNCTION
CALL costumePrinting FUNCTION
ASSIGN FUNCTION validCostumeIDReturn with parameter mainElements
to a variable as IDreturn
ASSIGN FUNCTION validQuantityReturn with parameters
mainElements,ID to a variable as Quantityreturn
APPEND IDreturn and Quantityreturn in cartReturn list
ASSIGN FUNCTION stockaddition with parameters mainElements, ID,
Quantity to a variable as mainElements
CALL writeindictionary(mainElements) FUNCTION
CREATE a boolean variable as continueloop and set its value to True
WHILE continueloop is equals to True
DISPLAY message as do the customer want to return more
costumes
DECLARE a variable as userConfirmation which asks the customer
whether they want to return another costume as well
IF userConfirmation equals to yes
CALL messageForReturn FUNCTION
CALL costumePrinting FUNCTION
ASSIGN FUNCTION validCostumeIDReturn with parameter
mainElements to a variable as IDreturn
ASSIGN FUNCTION validQuantityReturn with parameters
mainElements,ID to a variable as Quantityreturn
APPEND IDreturn and Quantityreturn in cartReturn list
ASSIGN FUNCTION stockaddition with parameters
mainElements, ID, Quantity to a variable as mainElements
CALL writeindictionary(mainElements) FUNCTION

23
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

ELIF userConfirmation equals no


ASSIGN nameofcustomer FUNCTION to a variable as
Namefothecustomer
ASSIGN email FUNCTION to a variable as mail
ASSIGN phone FUNCTION to a variable as contactNo
DECLARE a variable as days which asks the user for how
many days the costume was rented
DISPLAY Invoice Detail
DISPLAY Customer Name as Nameofthecustomer
DISPLAY Customer Email Address as mail
DISPLAY Customer Contact Number as contactNo
DISPLAY Costume Rented Date as dateAndTime
DISPLAY Returned costumes with Brand
FOR index in range of length of cartReturn
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 costumeBrand and SET value
of mainElements[creturnID][1] to it
DISPLAY index+1, costume name as creturnName,
costume Brand as creturnBrand
END FOR
DECLARE a variable as totalFine and set its value to 0
IF days is more than 5
DECLARE a variable as fineDays and ASSIGN days –
5 to it
DECLARE a variable as totalFine and ASSIGN
24
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

UPDATE secondContinueLoop to False


ELSE
DISPLAY please provide the value either true or false
ELIF usersOption is not equal to rent AND usersOption is not equal to return and
usersOption is not equal to exit
CALL invalid_message FUNCTION
ELIF usersOption equals to exit
UPDATE continueLoop to False
CALL messageForExit FUNCTION

26
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

2.4 Data Structures


In order to access data more effectively depending on the situation, data structures are a
way to organize data. Any programming language must include data structures as a
foundation upon which to build a program. As opposed to other programming languages,
Python makes it easier to master the fundamentals of these data structures
(GeeksforGeeks, 2022).

Figure 7: Data Structures in Python

Types of Data Structures in Python are:

1. Built-in Data Structures

• 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.

Figure 8: List data structure used in the program

• 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.

Figure 9: Dictionary data structure used in the program

2. User-Defined Data Structures

• 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.

Figure 10: Screenshot of the Integer data-type

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.

Figure 11: Screenshot of the float datatype

• 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

Figure 12: Screenshot of the String datatype

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.

Figure 13: Screenshot of the boolean variable

In the above figure a Boolean variable named as secondContinueLoop is set to


True.

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.

Implementation of Try and Except


Test Number 1
Objective To show the implementation of Try and Except
Action • Open the IDLE Shell

• While the program asks to enter the ID of the costume enter the String
value or any other values.

• Press Enter

• Invalid message appears in the screen.

Expected Message saying, “Enter Valid Input!!!!” appears.


Result
Actual Result Message saying, “Enter Valid Input!!!!” appeared.

Conclusion The testing was Successful

Table 2: Implementation of Try and Except

Figure 14: Implementation of Try and Except in code

41
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

Figure 15: Try and Except in IDLE Shell

Figure 16: Screenshot when valid ID is entered.

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.

• Enter negative value as “-1” for input

• Enter the non-existed value as “Rant or eexit or Nischal” for input

• A message appears in the screen.

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

Table 3: Providing negative and non-existed value as input.

Figure 17:Screenshot of providing negative and non-existed value as input.

43
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

4.3 Test 3

File generation of renting costume

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.

Expected • Multiple renting options to be presented


Result • complete renting costume
• showing output in shell
• showing the renting invoice in txt file
Actual Result • Multiple renting options is presented in the program
• complete renting costume is shown
• output in shell is showed
• renting invoice in txt file is showed
Conclusion The testing was Successful

Table 4: File generation of renting costume

44
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

45
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

Figure 18: Screenshot of Multiple costume rent

Figure 19: Screenshot of rent invoice in shell

46
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

Figure 20: Generation of text file and rent invoice printing

47
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

4.4 Test 4

File generation of returning

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.

Expected • Multiple returning options to be presented


Result • complete returning costume
• showing output in shell
• showing the returning invoice in txt file
Actual Result • Multiple returning options is presented in the program
• complete returning costume is shown
• output in shell is showed
• returning invoice in txt file is showed
Conclusion The testing was Successful

Table 5: File generation of renting costume

48
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

49
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

Figure 21: Screenshot of Multiple costume return

Figure 22:Screenshot of return invoice in shell

50
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

Figure 23: Generation of text file and return invoice printing

51
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

4.5 Test 5
Update in Stock of costume

4.5.1 Quantity reduction while renting costume

Test Number 5.1


Objective To show quantity reduction while renting costume
Action • Open the IDLE Shell

• While the program asks to select the choice rent, return or exit.

• Enter rent

• Rent multiple costume

• Enter no when the customer doesn’t want to rent other costumes.

• A bill in shell is created.

• A text file is generated with all the details.

• Update in stock of costume in costume.txt file

Expected Quantity should be reduced while renting costume in costume.txt file.


Result
Actual Result Quantity is reduced while renting costume in costume.txt file.

Conclusion The testing was Successful

Table 6: Stock reduction while renting costume.

Figure 24: Costume text file before stock reduction.

52
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

Figure 25: Full costume renting process

53
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

Figure 26: Quantity reduction in costume text file

54
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

4.5.2 Quantity addition while returning costume

Test Number 5.2


Objective To show quantity reduction while renting costume
Action • Open the IDLE Shell

• While the program asks to select the choice rent, return or exit.

• Enter return

• Return multiple costume

• Enter no when the customer doesn’t want to return other


costumes.

• A bill in shell is created.

• A text file is generated with all the details.

• Update in stock of costume in costume.txt file

Expected Quantity should be added while returning costume in costume.txt file.


Result
Actual Result Quantity is added while returning costume in costume.txt file.

Conclusion The testing was Successful

Table 7: Stock addition while returning costume

Figure 27: Costume text file before stock addition

55
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

Figure 28: Full costume returning process

56
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

Figure 29: Quantity addition in costume text file

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

Code for function.py

# defining a function for welcome message


def welcome_to_program():

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 for rent welcome message


def messageForRent():
print("\nWelcome for renting the costume!!")

# defining a function for return welcome message


def messageForReturn():
print("\nWelcome for returnig the costume!!Click on the provided options to return the
costume you have borrowed.\n")

# defining a function for exit message


def messageForExit():
print("\n\t Thank You for choosing and using our application.")

# defining a function for invalid input message


def invalid_message():
print("\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print("Invalid Input!!!!\nPlease select the value as per the provided options.")
print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n")

# 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

# declaring global variables and passing functions to them


contentsInFile=fileDataExtraction()
mainElements=get_dictionary(contentsInFile)

# 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

if(ID>=1 and ID<=len(mainElements)):


validInput=True
return ID
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 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")

Quantity=int(input("Enter the quantity of the costume: \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 asks the name of the customer


def nameofcustomer():
usersName=input("Enter the name of the customer: ")
return usersName

# defining a function which asks the mail of the customer


def email():
mail=input("Enter the email: ")
return mail

# defining a function which asks contact number of the customer


def phone():
contact=input("Enter your contact number: ")
return contact

# 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

def priceofthecostumes(mainElements, ID, Quantity):


price=str((mainElements[ID][2]).replace("$",""))
print("The renting price for a single costume is: "+ price)
priceofancostume= float(price) * Quantity
return priceofancostume

# 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

# defining a function for exception message


def forException():
print("\n==========================")
print("Please enter valid input!!!!")
print("============================")

64
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

Code for main.py

import datetime # importing date and time


from functions import * # importing every functions and items form the functions module

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("Costume-Id\tName of costume\tCostumes Brand\tCostumes


Price\tQuantity\tTotal Price\n")
file1.write("-----------------------------------------------------------------------------------------
\n")
# 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

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!!!")

elif usersOption!="rent" and usersOption!="return" and usersOption!="exit":


invalid_message()
elif usersOption=="exit":
continueLoop=False
messageForExit()

69
NISCHAL KHATIWADA
CS4051NI FUNDAMENTALS OF COMPUTING

70
NISCHAL KHATIWADA

You might also like