Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 127 additions & 77 deletions lab-oop_in_python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"metadata": {
"ExecuteTime": {
"end_time": "2025-10-08T13:04:01.130371Z",
"start_time": "2025-10-08T13:04:01.122328Z"
}
},
"source": [
"# Your code here\n",
"class Vehicle:\n",
" # Hint: Define __init__ method with parameters for max_speed and mileage\n",
" pass\n",
" def __init__(self, max_speed, mileage):\n",
" self.max_speed = max_speed\n",
" self.mileage = mileage\n",
"\n",
"\n",
"# Example instantiation\n",
"modelX = Vehicle() # Create an instance of Vehicle\n",
"modelX = Vehicle(10,100) # Create an instance of Vehicle\n",
"\n",
"# Print attributes\n",
"print(modelX.max_speed, modelX.mileage) # Expected output: (value of max_speed, value of mileage)"
]
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10 100\n"
]
}
],
"execution_count": 4
},
{
"cell_type": "markdown",
Expand All @@ -56,8 +71,21 @@
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2025-10-08T13:05:08.338450Z",
"start_time": "2025-10-08T13:05:08.328792Z"
}
},
"source": [
"# Your code here\n",
"class Vehicle:\n",
" pass\n",
"\n",
"# Example instantiation\n",
"my_vehicle = Vehicle()\n",
"print(type(my_vehicle)) # Expected output: <class '__main__.Vehicle'>"
],
"outputs": [
{
"name": "stdout",
Expand All @@ -67,15 +95,7 @@
]
}
],
"source": [
"# Your code here\n",
"class Vehicle:\n",
" pass\n",
"\n",
"# Example instantiation\n",
"my_vehicle = Vehicle()\n",
"print(type(my_vehicle)) # Expected output: <class '__main__.Vehicle'>"
]
"execution_count": 7
},
{
"cell_type": "markdown",
Expand All @@ -87,17 +107,12 @@
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class '__main__.Bus'>\n"
]
"metadata": {
"ExecuteTime": {
"end_time": "2025-10-08T13:05:26.509859Z",
"start_time": "2025-10-08T13:05:26.500373Z"
}
],
},
"source": [
"# Your code here\n",
"class Bus(Vehicle):\n",
Expand All @@ -106,7 +121,17 @@
"# Example instantiation\n",
"school_bus = Bus()\n",
"print(type(school_bus)) # Expected output: <class '__main__.Bus'>"
]
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class '__main__.Bus'>\n"
]
}
],
"execution_count": 8
},
{
"cell_type": "markdown",
Expand All @@ -118,30 +143,35 @@
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Base fare\n"
]
"metadata": {
"ExecuteTime": {
"end_time": "2025-10-08T13:07:04.350537Z",
"start_time": "2025-10-08T13:07:04.337318Z"
}
],
},
"source": [
"# Your code here\n",
"class Vehicle:\n",
" def fare(self):\n",
" return \"Base fare\"\n",
"\n",
"class Bus(Vehicle):\n",
" # Hint: Override fare method to include extra charges\n",
" pass\n",
" def fare(self):\n",
" return \"Base fare with extra charge\"\n",
"\n",
"school_bus = Bus()\n",
"print(school_bus.fare()) # Expected output: \"Base fare with extra charge\""
]
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Base fare with extra charge\n"
]
}
],
"execution_count": 10
},
{
"cell_type": "markdown",
Expand All @@ -153,17 +183,12 @@
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"White\n"
]
"metadata": {
"ExecuteTime": {
"end_time": "2025-10-08T13:07:14.881469Z",
"start_time": "2025-10-08T13:07:14.867772Z"
}
],
},
"source": [
"# Your code here\n",
"class Vehicle:\n",
Expand All @@ -176,7 +201,17 @@
"\n",
"school_bus = Vehicle(\"School Volvo\", 180, 12)\n",
"print(school_bus.color) # Expected output: \"White\""
]
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"White\n"
]
}
],
"execution_count": 11
},
{
"cell_type": "markdown",
Expand All @@ -188,17 +223,12 @@
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total Bus fare is: 5000\n"
]
"metadata": {
"ExecuteTime": {
"end_time": "2025-10-08T13:07:29.615517Z",
"start_time": "2025-10-08T13:07:29.600831Z"
}
],
},
"source": [
"# Your code here\n",
"class Vehicle:\n",
Expand All @@ -216,7 +246,17 @@
"\n",
"school_bus = Bus(\"School Volvo\", 12, 50)\n",
"print(\"Total Bus fare is:\", school_bus.fare()) # Expected output: Total Bus fare is: (calculated amount)"
]
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total Bus fare is: 5000\n"
]
}
],
"execution_count": 12
},
{
"cell_type": "markdown",
Expand All @@ -228,8 +268,17 @@
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2025-10-08T13:08:03.211646Z",
"start_time": "2025-10-08T13:08:03.203836Z"
}
},
"source": [
"# Your code here\n",
"school_bus = Bus(\"School Volvo\", 12, 50)\n",
"print(type(school_bus)) # Expected output: <class '__main__.Bus'>"
],
"outputs": [
{
"name": "stdout",
Expand All @@ -239,11 +288,7 @@
]
}
],
"source": [
"# Your code here\n",
"school_bus = Bus(\"School Volvo\", 12, 50)\n",
"print(type(school_bus)) # Expected output: <class '__main__.Bus'>"
]
"execution_count": 13
},
{
"cell_type": "markdown",
Expand All @@ -255,8 +300,16 @@
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"metadata": {
"ExecuteTime": {
"end_time": "2025-10-08T13:08:16.753553Z",
"start_time": "2025-10-08T13:08:16.743317Z"
}
},
"source": [
"# Your code here\n",
"print(isinstance(school_bus, Vehicle)) # Expected output: True or False based on inheritance"
],
"outputs": [
{
"name": "stdout",
Expand All @@ -266,10 +319,7 @@
]
}
],
"source": [
"# Your code here\n",
"print(isinstance(school_bus, Vehicle)) # Expected output: True or False based on inheritance"
]
"execution_count": 14
},
{
"cell_type": "markdown",
Expand Down