aboutsummaryrefslogtreecommitdiff
path: root/challenge-104/abigail/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-104/abigail/python/ch-2.py')
-rw-r--r--challenge-104/abigail/python/ch-2.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-104/abigail/python/ch-2.py b/challenge-104/abigail/python/ch-2.py
new file mode 100644
index 0000000000..b3f787dfe8
--- /dev/null
+++ b/challenge-104/abigail/python/ch-2.py
@@ -0,0 +1,28 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-2.py
+#
+
+tokens = 12
+max_take = 3
+
+
+while tokens > 0:
+ prompt = "How many tokens do you take? ({:2d} token{:s} are left) " . \
+ format (tokens, "" if tokens == 1 else "s")
+ take = input (prompt)
+ if take . isnumeric ():
+ take = int (take)
+ if 1 <= take <= max_take:
+ takes = max_take + 1 - take
+ print ("Computer takes {:d} token{:s}" . \
+ format (takes, "" if takes == 1 else "s"))
+ tokens = tokens - (max_take + 1)
+
+
+print ("Computer wins")