-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLAB3ex1.py
43 lines (36 loc) · 1.48 KB
/
LAB3ex1.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
class CoffeeMachine:
def __init__(self):
self.states = {'q0', 'q1', 'q2', 'q3', 'q4'}
self.initial_state = 'q0'
self.final_state = 'q4'
self.current_state = self.initial_state
self.transition_function = {
('q0', 'C'): 'q1',
('q0', 'T'): 'q2',
('q0', 'A'): 'q3',
('q0', 'H'): 'q4',
('q0', 'OK'): 'q0',
('q1', 'OK'): 'q4',
('q2', 'OK'): 'q4',
('q3', 'OK'): 'q4',
('q4', 'OK'): 'q0'
}
def process_input(self, input_char):
if (self.current_state, input_char) in self.transition_function:
self.current_state = self.transition_function[(self.current_state, input_char)]
def is_final(self):
return self.current_state == self.final_state
def main():
coffee_machine = CoffeeMachine()
while True:
print("Alegeți o băutură: C - cafea, T - ceai, A - cappuccino, H - ciocolată caldă, OK - confirmare")
user_input = input("Introduceți opțiunea dvs.: ").strip().upper()
if user_input in {'C', 'T', 'A', 'H', 'OK'}:
coffee_machine.process_input(user_input)
if coffee_machine.is_final():
print("Comanda finalizată. Vă mulțumim!")
break
else:
print("Opțiune invalidă. Vă rugăm să selectați una dintre opțiunile valide.")
if __name__ == "__main__":
main()