-
Notifications
You must be signed in to change notification settings - Fork 1
/
10.4.py
90 lines (66 loc) · 2.51 KB
/
10.4.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
"""
COMP.CS.100 Week Chapter
Name: Shamsur Raza Chowdhury <shamsurraza.chowdhury@tuni.fi>
Student Number: 050359798
This program
"""
class Product:
"""
This class defines a simplified product for sale in a store.
"""
# TODO: Define all the methods here. You can see what they are,
# what parameters they take, and what their return value is
# by examining the main-function carefully.
#
# You also need to consider which attributes the class needs.
#
# You are allowed to modify the main function, but your
# methods have to stay compatible with the original
# since the automatic tests assume that.
def __init__(self,name,price):
self.__name=name
self.__price=price
self.__percentage= 0.00
self.__newPrice= price
def printout(self):
print(self.__name)
print(f" price: {self.__price:.2f}")
print(f" sale%: {self.__percentage:.2f}")
def get_price(self):
return self.__newPrice
def set_sale_percentage(self,percent):
self.__percentage= percent
discount= self.__price*(percent/100)
self.__newPrice = self.__price - discount
def main():
################################################################
# #
# You can use the main-function to test your Product class. #
# The automatic tests will not use the main you submitted. #
# #
# Voit käyttää main-funktiota Product-luokkasi testaamiseen. #
# Automaattiset testit eivät käytä palauttamaasi mainia. #
# #
################################################################
test_products = {
"milk": 1.00,
"sushi": 12.95,
}
for product_name in test_products:
print("=" * 20)
print(f"TESTING: {product_name}")
print("=" * 20)
prod = Product(product_name, test_products[product_name])
prod.printout()
print(f"Normal price: {prod.get_price():.2f}")
print("-" * 20)
prod.set_sale_percentage(10.0)
prod.printout()
print(f"Sale price: {prod.get_price():.2f}")
print("-" * 20)
prod.set_sale_percentage(25.0)
prod.printout()
print(f"Sale price: {prod.get_price():.2f}")
print("-" * 20)
if __name__ == "__main__":
main()