-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoop task 1.py
101 lines (77 loc) · 2.3 KB
/
oop task 1.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
# 1. Explain in few words what we mean by a class give and example
class is some of few functions that we call them with class name
EX:
class Bank:
c1= Bank
#2. create a simple class names calculator
class Calc:
def __init__(self):
c1 = Calc
#3. Create a constructor that prints Welcome message
class Calc:
def __init__(self):
print('welcome')
c1 = Calc
#4. Add 2 methods to the class sum & mull
class Calc:
def __init__(self):
print('welcome')
def mysum(self,x,y):
result= x+y
print(result)
def mull(self,x,y):
result= x*y
print(result)
c1 = Calc
c1.mysum(5,6)
c1.mull(5,6)
#5. The sum method return the sum of 2 arguments x and y
class Calc:
def __init__(self):
print('welcome')
def mysum(self,x,y):
result= x+y
return result
c1 = Calc
print(result)
#6. The mull method return the multiplication of the arguments x and y
class Calc:
def __init__(self):
print('welcome')
def mysum(self,x,y):
result= x*y
return result
#7. Take an object from the class
class Calc:
def mysum(self,x,y):
return x+y
print(x+y)
c1 = Calc()
c1.mysum(5,6)
#8. Call the sum method with 10 , 20
class Calc:
def mysum(self,x,y):
return x+y
print(x+y)
c1 = Calc()
c1.mysum(10,20)
#9. Call the mull method with 10 , 20
class Calc:
def mull(self,x,y):
return x*y
print(x*y)
c1= Calc()
c1.mull(10,20)
#10. Explain in few words why we call the self in methods
self its to defin a variable that equal the class name
to make kontakt with class and self should always have place in functions
#11. What we mean with OOP 4 Pillars
encapsulation
inheritance
polymorphism
abstraction
we should use thise 4 methode when we writing code
#12. Why we use OOP in our code
it make code modular and faster and all programing language use oop :
Overall, OOP helps developers write better-organized, more maintainable, and more extensible code that is easier to understand and collaborate on, making software development more efficient and effective.
#Python OOP Tasks Part 1