-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday01_classesandobjects.py
More file actions
77 lines (46 loc) · 1.64 KB
/
Copy pathday01_classesandobjects.py
File metadata and controls
77 lines (46 loc) · 1.64 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
#------------------------------------------------------------------------------------------------------------------
# classes and objects
#------------------------------------------------------------------------------------------------------------------
#1. Car class with methods
class Car:
def start(self):
print("Car Started.")
c1 = Car()
c1.start()
#------------------------------------------------------------------------------------------------------------------
#2.Student class with attributes
class Student:
s1 = Student()
s1.name = "Sid"
s1.age = 19
print("Name:", s1.name)
print("Age:", s1.age)
#------------------------------------------------------------------------------------------------------------------
#3.Book class
class Books:
def details(self, name, author, price):
self.name = name
self.author = author
self.price = price
b1 = Books()
b2 = Books()
b1.details("Mountains and Rivers","Willey",500.00)
b2.details("Next to you","Harry", 750.00)
print("\nTitle:", b1.name, "\nAuthor:", b1.author, "\nPrice:", b1.price)
print("\nTitle:", b2.name, "\nAuthor:", b2.author, "\nPrice:", b2.price)
#--------------------------------------------------------------------------------------------------------------------
#4. Rectangle class
class Rectangle:
def area(self,length,breadth):
self.length = length
self.breadth = breadth
def show_area(self):
print("\nLength=", self.length, "\nBreadth=", self.breadth)
res = self.length * self.breadth
print("Area of the Rectangle:",res)
R1 = Rectangle()
R2 = Rectangle()
R1.area(12, 3)
R2.area(50,25)
R1.show_area()
R2.show_area()