diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-03-22 00:30:30 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-03-22 00:30:30 +0000 |
| commit | 816a93d813adbad0616374a025065e09996c426f (patch) | |
| tree | 6bea2a048066d44ffd3b10f298f30df6b4309bf7 /challenge-104/laurent-rosenfeld/python/ch-2.py | |
| parent | ce13ffed92a5204f80e4d010f246bd92892618c4 (diff) | |
| download | perlweeklychallenge-club-816a93d813adbad0616374a025065e09996c426f.tar.gz perlweeklychallenge-club-816a93d813adbad0616374a025065e09996c426f.tar.bz2 perlweeklychallenge-club-816a93d813adbad0616374a025065e09996c426f.zip | |
- Added C, Gembase, Python and Ruby by Laurent Rosenfeld.
Diffstat (limited to 'challenge-104/laurent-rosenfeld/python/ch-2.py')
| -rw-r--r-- | challenge-104/laurent-rosenfeld/python/ch-2.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-104/laurent-rosenfeld/python/ch-2.py b/challenge-104/laurent-rosenfeld/python/ch-2.py new file mode 100644 index 0000000000..d260e649dc --- /dev/null +++ b/challenge-104/laurent-rosenfeld/python/ch-2.py @@ -0,0 +1,24 @@ +heap_count = 12 +max_picks = 3 +def pick_one_val(count): + pick = input("There are " + str(count) + " tokens left. How many tokens do you pick? "); + return pick + +who_starts = input("Please say who starts (Y/I):") +if who_starts == "Y": + pick = pick_one_val(heap_count) + heap_count = heap_count - int(pick) +while True: + pick = heap_count % (max_picks + 1) + if pick == 0: + pick = 1 + print("I picked ", str(pick), " tokens.") + heap_count = heap_count - int(pick) + if heap_count == 0: + print("I won!"); + break + pick = pick_one_val(heap_count) + heap_count = heap_count - int(pick) + if heap_count == 0: + print ("You won!") + break |
