-
Notifications
You must be signed in to change notification settings - Fork 4
/
assignment_25_1_2022.py
124 lines (83 loc) · 2.98 KB
/
assignment_25_1_2022.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
import requests
# 25/1/2022 assignment
# 1. We have a report on the number of flu vaccinations in a class of 40 people.
# It has the following numbers: never:8 once: 10 twice: 4 Threetimes:6
# What is the mean number of the times those people have been vaccinated?
def mean_vaccination():
never = 8
once = 10
twice = 4
threetimes = 6
total = never + once + twice + threetimes
mean = total / 4
print("The mean number of the times those people have been vaccinated is:", mean)
mean_vaccination()
# 2. Create a store class that allow customers purchase items in your store
from store import Store, Product
items = []
try:
products = requests.get('https://hub.dummyapis.com/products?noofRecords=10&idStarts=1001¤cy=usd', timeout=10).json()
except:
print("Error while fetching data")
exit(-1)
for product in products:
items.append(Product(product['name'], int(float(product['price'][2:]))))
store = Store("CIT Store", items)
print(store.products)
# add a product to the store
print(store.add_products(Product("Coffee", 10)))
print(store.add_products(Product("Tea", 5)))
print(store.inflation(0.1))
print(store.print_products())
print(store.set_clearance(0.5))
print(store.print_products())
# sell a product
print(store.sell_product(Product('Tea')))
# remove a product
print(store.remove_products(Product('coffee')))
# 3. Create a polymorphism class funtion.
class Polymorphism():
def __init__(self, name, age):
self.name = name
self.age = age
def __str__(self):
return f"{self.name} is {self.age} years old"
def make_sound(self):
print(f"{self.name} says hello")
def move(self):
print(f"{self.name} moves")
class Cat(Polymorphism):
def __init__(self, name, age, fur_color):
super().__init__(name, age)
self.fur_color = fur_color
def __str__(self):
return f"{self.name} is {self.age} years old and has {self.fur_color} fur"
def make_sound(self):
print(f"{self.name} says meow")
class Dog(Polymorphism):
def __init__(self, name, age, fur_color):
super().__init__(name, age)
self.fur_color = fur_color
def __str__(self):
return f"{self.name} is {self.age} years old and has {self.fur_color} fur"
def make_sound(self):
print(f"{self.name} says woof")
cat = Cat("Fluffy", 2, "white")
dog = Dog("Fido", 3, "brown")
print(cat)
print(dog)
cat.make_sound()
dog.make_sound()
"""
1.We have a report on the number of flu vaccinations in a class of 40 people.
It has the following numbers: never:10 once: 15 twice: 7 Threetimes:8
What is the mean number of the times those people have been vaccinated?
"""
number_of_people = 40
number_of_never = 10
number_of_once = 15
number_of_twice = 7
number_of_threetimes = 8
sum_vaccinated = number_of_once + number_of_twice + number_of_threetimes
mean_vaccinated = sum_vaccinated / number_of_people
print(f"The mean number of the times those people have been vaccinated is: {mean_vaccinated}")