Skip to content

Commit 3168afd

Browse files
committed
Added Classes and Objects - Lab
1 parent 87ce6a7 commit 3168afd

File tree

6 files changed

+86
-0
lines changed

6 files changed

+86
-0
lines changed

OOP/2.Classes and Objects/# TODO.txt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Vehicle:
2+
3+
def __init__(self, mileage, max_speed=150):
4+
self.mileage = mileage
5+
self.max_speed = max_speed
6+
self.gadgets = []
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Point:
2+
3+
def __init__(self, x, y):
4+
self.x = x
5+
self.y = y
6+
7+
def set_x(self, new_x):
8+
self.x = new_x
9+
10+
def set_y(self, new_y):
11+
self.y = new_y
12+
13+
def __str__(self):
14+
return f"The point has coordinates ({self.x},{self.y})"
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Circle:
2+
pi = 3.14
3+
4+
def __init__(self, radius):
5+
self.radius = radius
6+
7+
def set_radius(self, new_radius):
8+
self.radius = new_radius
9+
10+
def get_area(self):
11+
return self.radius ** 2 * Circle.pi
12+
13+
def get_circumference(self):
14+
return self.radius * 2 * Circle.pi
15+
16+
17+
''' TEST '''
18+
# circle = Circle(10)
19+
# circle.set_radius(12)
20+
# print(circle.get_area())
21+
# print(circle.get_circumference())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Glass:
2+
capacity = 250
3+
4+
def __init__(self):
5+
self.content = 0
6+
7+
def fill(self, ml):
8+
if self.content + ml <= Glass.capacity:
9+
self.content += ml
10+
return f"Glass filled with {ml} ml"
11+
return f"Cannot add {ml} ml"
12+
13+
def empty(self):
14+
self.content = 0
15+
return "Glass is now empty"
16+
17+
def info(self):
18+
return f"{Glass.capacity - self.content} ml left"
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Smartphone:
2+
3+
def __init__(self, memory):
4+
self.memory = memory
5+
self.apps = []
6+
self.is_on = False
7+
8+
def power(self):
9+
self.is_on = False if self.is_on else True
10+
11+
def install(self, app, app_memory):
12+
if self.memory - app_memory >= 0 and self.is_on:
13+
self.memory -= app_memory
14+
self.apps.append(app)
15+
return f"Installing {app}"
16+
17+
elif self.memory - app_memory >= 0:
18+
return f"Turn on your phone to install {app}"
19+
20+
return f"Not enough memory to install {app}"
21+
22+
def status(self):
23+
return f"Total apps: {len(self.apps)}. Memory left: {self.memory}"
24+

0 commit comments

Comments
 (0)