-
Notifications
You must be signed in to change notification settings - Fork 2
/
Sale_rep.py
142 lines (99 loc) · 3.86 KB
/
Sale_rep.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# -*- coding: utf-8 -*-
"""
Created on: 30/05/2020
@author: Rohan Kumara
"""
class Pants:
"""The Pants class represents an article of clothing sold in a store
"""
def __init__(self, color, waist_size, length, price):
"""Method for initializing a Pants object
Args:
color (str)
waist_size (int)
length (int)
price (float)
Attributes:
color (str): color of a pants object
waist_size (str): waist size of a pants object
length (str): length of a pants object
price (float): price of a pants object
"""
self.color = color
self.waist_size = waist_size
self.length = length
self.price = price
def change_price(self, new_price):
"""The change_price method changes the price attribute of a pants object
Args:
new_price (float): the new price of the pants object
Returns: None
"""
self.price = new_price
def discount(self, percentage):
"""The discount method outputs a discounted price of a pants object
Args:
percentage (float): a decimal representing the amount to discount
Returns:
float: the discounted price
"""
return self.price * (1 - percentage)
class SalesPerson:
"""The SalesPerson class represents an employee in the store
"""
def __init__(self, first_name, last_name, employee_id, salary):
"""Method for initializing a SalesPerson object
Args:
first_name (str)
last_name (str)
employee_id (int)
salary (float)
Attributes:
first_name (str): first name of the employee
last_name (str): last name of the employee
employee_id (int): identification number of the employee
salary (float): yearly salary of the employee
pants_sold (list): a list of pants objects sold by the employee
total_sales (float): sum of all sales made by the employee
"""
self.first_name = first_name
self.last_name = last_name
self.employee_id = employee_id
self.salary = salary
self.pants_sold = []
self.total_sales = 0
def sell_pants(self, pants_object):
"""The sell_pants method appends a pants object to the pants_sold attribute
Args:
pants_object (obj): a pants object that was sold
Returns: None
"""
self.pants_sold.append(pants_object)
def display_sales(self):
"""The display_sales method prints out all pants that have been sold
Args: None
Returns: None
"""
for pants in self.pants_sold:
print('color: {}, waist_size: {}, length: {}, price: {}'\
.format(pants.color, pants.waist_size, pants.length, pants.price))
def calculate_sales(self):
"""The calculate_sales method sums the total price of all pants sold
Args: None
Returns:
float: sum of the price for all pants sold
"""
total = 0
for pants in self.pants_sold:
total += pants.price
self.total_sales = total
return total
def calculate_commission(self, percentage):
"""The calculate_commission method outputs the commission based on sales
Args:
percentage (float): the commission percentage as a decimal
Returns:
float: the commission due
"""
sales_total = self.calculate_sales()
return sales_total * percentage