Skip to content

Commit 788a8cb

Browse files
author
Bimo
committed
add python to state machine
1 parent 9c5a37c commit 788a8cb

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Imagine a machine that gives you a quarter once you put in 25 cents. I suppose if you really like
3+
gumballs that is in someway useful. The machine will wait until it has reached a state of 25 cents,
4+
then it will spit out a quarter. The machine is totally oblivious to what coins were added to reach
5+
its current state, all it knows is the state it is in, which is how it achieves the "no memory" standard.
6+
(at least conceptually)
7+
"""
8+
from enum import Enum
9+
10+
class coins(Enum):
11+
penny = 1
12+
nickel = 5
13+
dime = 10
14+
quarter = 25
15+
16+
17+
def main():
18+
state = 0
19+
20+
while state <= 25:
21+
22+
print(f"Balance: {state}")
23+
coin = input("Please insert a coin(penny, nickel, dime, quarter): ")
24+
try:
25+
state+=coins[coin].value
26+
except:
27+
print("That's not a coin")
28+
continue
29+
30+
print("Thanks, here's your quarter")
31+
32+
main()

0 commit comments

Comments
 (0)