-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW10_RobotCleaner.py
85 lines (68 loc) · 2.32 KB
/
HW10_RobotCleaner.py
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
import time
class LowBattery(Exception):
pass
class NoCharge(Exception):
pass
class FullTrash(Exception):
pass
class NoWater(Exception):
pass
class RobotCleaner:
max_energy, max_trash, max_water = 100, 500, 500
min_energy, min_trash, min_water = 0, 0, 0
work_energy = 5
work_trash = 50
work_water = 100
def __init__(self, charge_battery, trash_can, water_quantity):
self.charge_battery = float(charge_battery)
self.trash_can = float(trash_can)
self.water_quantity = float(water_quantity)
if self.charge_battery < 0:
self.charge_battery = 0.0
elif self.trash_can < 0:
self.trash_can = 0.0
elif self.water_quantity < 0:
self.water_quantity = 0.0
def wash(self):
if self.water_quantity > 0:
self.water_quantity -= self.work_water
print(f"I wash your floor! I have {self.water_quantity} ml of water in my stomach!")
else:
raise NoWater
def vacuum_cleaner(self):
if self.charge_battery > 10:
self.charge_battery -= self.work_energy
print(f"I move to clean your house! My charge is {self.charge_battery}!")
elif 1 < self.charge_battery <= 10:
self.charge_battery -= 1
raise LowBattery
else:
raise NoCharge
if self.trash_can < 500:
self.trash_can += self.work_trash
print(f"I clean your house from trash! I got {self.trash_can} ml trash in my stomach!")
else:
raise FullTrash
def move(self):
i = 0
while True:
print(f"//////{i}/////")
try:
self.vacuum_cleaner()
except FullTrash:
print("Help! I need to empty my stomach!")
self.trash_can = 0
except LowBattery:
print(f"Hey, I'm running to charge myself! My charge is {self.charge_battery}!")
except NoCharge:
print("I can't get charging myself. Bring me to charging place!")
exit()
try:
self.wash()
except NoWater:
print("My water is off. I only vacuum clean!")
i += 1
time.sleep(1)
# zhorick = RobotCleaner(100, 0, 1000)
#
# zhorick.move()