-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek5assignment.py
More file actions
64 lines (52 loc) · 2.1 KB
/
week5assignment.py
File metadata and controls
64 lines (52 loc) · 2.1 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
# Define the Smartphone class
class Smartphone:
def __init__(self, brand, model, storage, battery_life, price):
self.brand = brand
self.model = model
self.storage = storage
self.battery_life = battery_life
self.price = price
def describe(self):
return f"{self.brand} {self.model} with {self.storage}GB storage, {self.battery_life}h battery life, priced at ${self.price}."
def check_battery(self):
if self.battery_life > 20:
return "Battery life is good."
else:
return "Battery life is low. Consider charging."
# Define the Smartwatch class that inherits from Smartphone
class Smartwatch(Smartphone):
def __init__(self, brand, model, storage, battery_life, price, strap_material, waterproof):
super().__init__(brand, model, storage, battery_life, price)
self.strap_material = strap_material
self.waterproof = waterproof
def describe(self):
return f"{self.brand} {self.model} with {self.storage}GB storage, {self.battery_life}h battery life, {self.strap_material} strap, waterproof: {self.waterproof}, priced at ${self.price}."
def check_waterproof(self):
return "This smartwatch is waterproof." if self.waterproof else "This smartwatch is not waterproof."
# Create instances of Smartphone and Smartwatch
phone = Smartphone("Apple", "iPhone 14", 128, 30, 999)
watch = Smartwatch("Samsung", "Galaxy Watch 4", 16, 48, 299, "silicone", True)
# Display descriptions and check battery status
print(phone.describe())
print(phone.check_battery())
print(watch.describe())
print(watch.check_battery())
print(watch.check_waterproof())
# Define the base class Vehicle
class Vehicle:
def move(self):
pass
# Define the Car class that inherits from Vehicle
class Car(Vehicle):
def move(self):
print("Driving 🚗")
# Define the Plane class that inherits from Vehicle
class Plane(Vehicle):
def move(self):
print("Flying ✈️")
# Create instances of Car and Plane
my_car = Car()
my_plane = Plane()
# Call the move method on each instance
my_car.move()
my_plane.move()