-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAirConditionerSimulator
More file actions
80 lines (70 loc) · 2.67 KB
/
AirConditionerSimulator
File metadata and controls
80 lines (70 loc) · 2.67 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
class AirConditionerSimulator:
def __init__(self):
self.temperature = 26 # 初始温度为26度
self.mode = 5 # 初始模式为常温
self.running = False
def start(self):
while True:
if not self.running:
print("空调待机模式")
print("1. 设置温度")
print("2. 设置冷热模式")
print("9. 启动空调")
print("0. 退出")
choice = input("请输入选项: ")
if choice == '1':
self.set_temperature()
elif choice == '2':
self.set_mode()
elif choice == '9':
self.start_air_conditioner()
elif choice == '0':
break
else:
print("无效的选项,请重新输入")
else:
print(f"空调运行中 - 温度: {self.temperature}度, 模式: {'热风' if self.mode == 8 else '冷风' if self.mode == 2 else '常温'}")
print("0. 暂停空调")
choice = input("请输入选项: ")
if choice == '0':
self.pause_air_conditioner()
def set_temperature(self):
while True:
print(f"当前温度: {self.temperature}度")
print("1. 上升温度")
print("2. 下降温度")
print("0. 保存温度并返回待机模式")
choice = input("请输入选项: ")
if choice == '1':
self.temperature += 1
elif choice == '2':
self.temperature -= 1
elif choice == '0':
break
else:
print("无效的选项,请重新输入")
def set_mode(self):
while True:
print(f"当前模式: {'热风' if self.mode == 8 else '冷风' if self.mode == 2 else '常温'}")
print("1. 选择热风")
print("2. 选择冷风")
print("5. 选择常温")
print("0. 保存冷热模式并返回待机模式")
choice = input("请输入选项: ")
if choice == '1':
self.mode = 8
elif choice == '2':
self.mode = 2
elif choice == '5':
self.mode = 5
elif choice == '0':
break
else:
print("无效选项,请重新输入")
def start_air_conditioner(self):
self.running = True
def pause_air_conditioner(self):
self.running = False
if __name__ == "__main__":
ac_simulator = AirConditionerSimulator()
ac_simulator.start()