-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclassess-and-objects.py
More file actions
99 lines (62 loc) · 1.59 KB
/
classess-and-objects.py
File metadata and controls
99 lines (62 loc) · 1.59 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
# # simple class
# class MyClass:
# variable = "blah"
#
# def function(self):
# print("This is a message inside the class.")
#
# # create object of the class
# myobjectx = MyClass()
#
# # accessing the object variable
# myobjectx.variable
#
#
# # multi object in the same class
# myobjectx = MyClass()
# myobjecty = MyClass()
#
# myobjecty.variable = "yackity"
#
# # Then print out both values
# print(myobjectx.variable)
# print(myobjecty.variable)
#
#
# # acessing object function
# myobjectx.function()
class MobilSaya():
def __init__(self, brand, color):
self.brand = brand
self.color = color
def testing_1(self):
print("Testing: %s" % self.name)
def get_data_mobil(self):
print("Brand: %s, Color: %s" % (self.brand, self.color))
mobil1 = MobilSaya("Honda", "Red")
# print(mobil1.testing_1())
# print(dir(mobil1))
print(mobil1.get_data_mobil())
print('-------------------------------------')
mobil1.brand = "Hyundai"
print(mobil1.get_data_mobil())
'''
EXERCISE
We have a class defined for vehicles.
Create two new vehicles called car1 and car2.
Set car1 to be a red convertible worth $60,000.00 with a name of Fer,
and car2 to be a blue van named Jump worth $10,000.00.
'''
# define the Vehicle class
class Vehicle:
name = ""
kind = "car"
color = ""
value = 100.00
def description(self):
desc_str = "%s is a %s %s worth $%.2f." % (self.name, self.color, self.kind, self.value)
return desc_str
# # your code goes here
# # test code
# print(car1.description())
# print(car2.description())