-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask5b.py
More file actions
123 lines (94 loc) · 3.08 KB
/
task5b.py
File metadata and controls
123 lines (94 loc) · 3.08 KB
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
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 5 16:51:30 2019
@author: Ola
Python challenge by kodolamacz.pl
Task 5: Advanced object oriented programming
"""
from abc import ABC, abstractmethod
import math
class Wezel(ABC):
@abstractmethod
def nazwa(self):
pass
@abstractmethod
def oblicz_wartosc(self):
pass
def informacje(self):
print(f"Wynikiem operacji {self.nazwa()} jest wartosc {self.oblicz_wartosc()} \n")
class Wartosc(Wezel):
def __init__(self, czynnik):
self.czynnik = czynnik
def nazwa(self):
return "wartosc"
def oblicz_wartosc(self):
return float(self.czynnik)
class Suma(Wezel):
def __init__(self, czynnik1, czynnik2):
self.czynnik1 = czynnik1.oblicz_wartosc()
self.czynnik2 = czynnik2.oblicz_wartosc()
def nazwa(self):
return "sumowania"
def oblicz_wartosc(self):
return self.czynnik1 + self.czynnik2
def informacje(self):
print(f"Liczby do operacji matematycznej: {self.czynnik1}, {self.czynnik2}")
super().informacje()
class Roznica(Wezel):
def __init__(self, czynnik1, czynnik2):
self.czynnik1 = czynnik1.oblicz_wartosc()
self.czynnik2 = czynnik2.oblicz_wartosc()
def nazwa(self):
return "odejmowania"
def oblicz_wartosc(self):
return self.czynnik1 - self.czynnik2
def informacje(self):
print(f"Liczby do operacji matematycznej: {self.czynnik1}, {self.czynnik2}")
super().informacje()
class Iloczyn(Wezel):
def __init__(self, czynnik1, czynnik2):
self.czynnik1 = czynnik1.oblicz_wartosc()
self.czynnik2 = czynnik2.oblicz_wartosc()
def nazwa(self):
return "mnozenia"
def oblicz_wartosc(self):
return self.czynnik1*self.czynnik2
def informacje(self):
print(f"Liczby do operacji matematycznej: {self.czynnik1}, {self.czynnik2}")
super().informacje()
class Iloraz(Wezel):
def __init__(self, czynnik1, czynnik2):
self.czynnik1 = czynnik1.oblicz_wartosc()
self.czynnik2 = czynnik2.oblicz_wartosc()
def nazwa(self):
return "dzielenia"
def oblicz_wartosc(self):
return self.czynnik1/self.czynnik2
def informacje(self):
print(f"Liczby do operacji matematycznej: {self.czynnik1}, {self.czynnik2}")
super().informacje()
class Silnia(Wezel):
def __init__(self, czynnik):
self.czynnik = czynnik.oblicz_wartosc()
def nazwa(self):
return "silni"
def oblicz_wartosc(self):
return math.factorial(self.czynnik)
def informacje(self):
print(f"Liczby do operacji matematycznej: {self.czynnik}")
super().informacje()
def test():
liczba1 = Wartosc(6)
liczba2 = Wartosc(2)
suma = Suma(liczba1, liczba2)
suma.informacje()
roznica = Roznica(liczba1, liczba2)
roznica.informacje()
iloczyn = Iloczyn(liczba1, liczba2)
iloczyn.informacje()
iloraz = Iloraz(liczba1, liczba2)
iloraz.informacje()
silnia = Silnia(liczba1)
silnia.informacje()
if __name__ == "__main__":
test()