-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOP.py
More file actions
44 lines (30 loc) · 829 Bytes
/
OOP.py
File metadata and controls
44 lines (30 loc) · 829 Bytes
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
class Car:
# comntructor
def __init__(self,brand,color):
self.brand=brand
self.color=color
# Method
def drive(self):
print(self.brand,f"is my dream Car and {self.color} in color")
# Create object
car1=Car("Lexus","White")
car1.drive()
car2=Car("Bentley","Beige")
car2.drive()
car3=Car("Harier","Purple")
car3.drive()
car4=Car("Tx","Yellow")
car4.drive()
class Fruits:
def __init__(type,fruit,color,price) :
type.fruit=fruit
type.color=color
type.price=price
def buy(type):
print(type.fruit,f"is my favourite fruit and {type.price} in cash and {type.color} in color")
fruit1=Fruits("Mango","Yellow","ksh.100")
fruit1.buy()
fruit2=Fruits("Banana","Yellow","ksh.100")
fruit2.buy()
fruit3=Fruits("Apple","Green","ksh.50")
fruit3.buy()