From bc3d0296c5d5a6702c877f676a843c23afe2e4ce Mon Sep 17 00:00:00 2001 From: Alvaro Frias Garay Date: Wed, 3 Mar 2021 13:08:24 -0300 Subject: [PATCH 1/3] Added python port of russianroulette --- 76 Russian Roulette/python/russianroulette.py | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 76 Russian Roulette/python/russianroulette.py diff --git a/76 Russian Roulette/python/russianroulette.py b/76 Russian Roulette/python/russianroulette.py new file mode 100644 index 00000000..a1391608 --- /dev/null +++ b/76 Russian Roulette/python/russianroulette.py @@ -0,0 +1,55 @@ +from random import random + +NUMBER_OF_ROUNDS = 9 + + +def initial_message(): + print(" " * 28 + "Russian Roulette") + print(" " * 15 + "Creative Computing Morristown, New Jersey\n\n\n") + print("This is a game of >>>>>>>>>>Russian Roulette.\n") + print("Here is a Revolver.") + + +def parse_input(): + correct_input = False + while not correct_input: + try: + i = int(input('?')) + correct_input = True + except ValueError: + print('Number expected...') + return i + + +initial_message() +while True: + dead = False + n = 0 + print("Type \'1\' to Spin chamber and pull trigger") + print("Type \'2\' to Give up") + print("Go") + while not dead: + i = parse_input() + + if i == 2: + break + + if random() > 0.8333333333333334: + dead = True + else: + print("- CLICK -\n") + n += 1 + + if n > NUMBER_OF_ROUNDS: + break + if dead: + print("BANG!!!!! You're Dead!") + print("Condolences will be sent to your relatives.\n\n\n") + print("...Next victim...") + else: + if n > NUMBER_OF_ROUNDS: + print("You win!!!!!") + print("Let someone else blow his brain out.") + else: + print(" Chicken!!!!!\n\n\n") + print("...Next victim....") From dfa0584fdd9f1dba0678e334a1f53ec4282845fb Mon Sep 17 00:00:00 2001 From: Alvaro Frias Garay Date: Wed, 3 Mar 2021 13:24:39 -0300 Subject: [PATCH 2/3] Added history comments and porting notes --- 76 Russian Roulette/python/russianroulette.py | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/76 Russian Roulette/python/russianroulette.py b/76 Russian Roulette/python/russianroulette.py index a1391608..508fd15a 100644 --- a/76 Russian Roulette/python/russianroulette.py +++ b/76 Russian Roulette/python/russianroulette.py @@ -1,3 +1,21 @@ +######################################################## +# +# Russian Roulette +# +# From Basic Computer Games (1978) +# +# In this game, you are given by the computer a +# revolver loaded with one bullet and five empty +# chambers. You spin the chamber and pull the trigger +# by inputting a "1", or, if you want to quit, input +# a "2". You win if you play ten times and are still +# alive. +# Tom Adametx wrote this program while a student at +# Curtis Jr. High School in Sudbury, Massachusetts. +# +######################################################## + + from random import random NUMBER_OF_ROUNDS = 9 @@ -14,7 +32,7 @@ def parse_input(): correct_input = False while not correct_input: try: - i = int(input('?')) + i = int(input('? ')) correct_input = True except ValueError: print('Number expected...') @@ -53,3 +71,22 @@ while True: else: print(" Chicken!!!!!\n\n\n") print("...Next victim....") + + +######################################################## +# Porting Notes +# +# Altough the description says that accepts "1" or "2", +# the original game accepts any number as input, and +# if it's different of "2" the program considers +# as if the user had passed "1". That feature was +# kept in this port. +# Also, in the original game you must "pull the trigger" +# 11 times instead of 10 in orden to win, +# given that N=0 at the beginning and the condition to +# win is "IF N > 10 THEN 80". That was fixed in this +# port, asking the user to pull the trigger only ten +# times, tough the number of round can be set changing +# the constant NUMBER_OF_ROUNDS. +# +######################################################## From 893da91b0c6901171f219c464d58a7858c815761 Mon Sep 17 00:00:00 2001 From: Alvaro Frias Garay Date: Wed, 3 Mar 2021 13:26:19 -0300 Subject: [PATCH 3/3] infimous change to print so it can look exactly like the original --- 76 Russian Roulette/python/russianroulette.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/76 Russian Roulette/python/russianroulette.py b/76 Russian Roulette/python/russianroulette.py index 508fd15a..bac04dc6 100644 --- a/76 Russian Roulette/python/russianroulette.py +++ b/76 Russian Roulette/python/russianroulette.py @@ -67,7 +67,7 @@ while True: else: if n > NUMBER_OF_ROUNDS: print("You win!!!!!") - print("Let someone else blow his brain out.") + print("Let someone else blow his brain out.\n") else: print(" Chicken!!!!!\n\n\n") print("...Next victim....")