Simple command-line roulette game Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Die Roller for command lineCommand line calculus programCommand-line-based capacitance decodingLittle command line video grabberProcessing command line parametersPython3 command line chessCommand line IRC clientSimplifying parsing command-line argumentsCommand Line CalendarCommand-Line Poker Showdown
How to call a function with default parameter through a pointer to function that is the return of another function?
Dating a Former Employee
Identifying polygons that intersect with another layer using QGIS?
2001: A Space Odyssey's use of the song "Daisy Bell" (Bicycle Built for Two); life imitates art or vice-versa?
Seeking colloquialism for “just because”
Why did the IBM 650 use bi-quinary?
How to find all the available tools in macOS terminal?
Why was the term "discrete" used in discrete logarithm?
A coin, having probability p of landing heads and probability of q=(1-p) of landing on heads.
Echoing a tail command produces unexpected output?
How to tell that you are a giant?
prime numbers and expressing non-prime numbers
Why do we bend a book to keep it straight?
How would the world control an invulnerable immortal mass murderer?
How can I make names more distinctive without making them longer?
Can an alien society believe that their star system is the universe?
How to run gsettings for another user Ubuntu 18.04.2 LTS
What does the "x" in "x86" represent?
What would be the ideal power source for a cybernetic eye?
In predicate logic, does existential quantification (∃) include universal quantification (∀), i.e. can 'some' imply 'all'?
Why are there no cargo aircraft with "flying wing" design?
Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?
What exactly is a "Meth" in Altered Carbon?
If a contract sometimes uses the wrong name, is it still valid?
Simple command-line roulette game
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Die Roller for command lineCommand line calculus programCommand-line-based capacitance decodingLittle command line video grabberProcessing command line parametersPython3 command line chessCommand line IRC clientSimplifying parsing command-line argumentsCommand Line CalendarCommand-Line Poker Showdown
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
I developed a simple command-line roulette game. Your only options are betting on color, but you can bet multiple times in one round
import copy
import distutils.core
from time import sleep
from random import randint
red_slots=(1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36)
black_slots=(2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35)
master_color_dict='red':0,'black':0,'green':0
quit = False
bal = 500
def roll(num,bet_choice,color_choice):
color_dict = master_color_dict.copy()
hits = 0
for _ in range(num):
sleep(.1)
r = randint(0,36); print(r,end=" ")
if r in red_slots:
color_dict['red']+=1
if color_choice == 'red':
hits+=1
print(' -- HIT x'+str(hits))
else:
print()
elif r in black_slots:
color_dict['black']+=1
if color_choice == 'black':
hits+=1
print(' -- HIT x'+str(hits))
else:
print()
elif r == 0:
color_dict['green']+=1
if color_choice == 'green':
hits+=1
print(' -- HIT x'+str(hits))
else:
print()
if color_choice == 'red':
return color_dict[color_choice]*bet_choice - color_dict['black']*bet_choice - color_dict['green']*bet_choice
elif color_choice == 'black':
return color_dict[color_choice]*bet_choice - color_dict['red']*bet_choice - color_dict['green']*bet_choice
elif color_choice == 'green':
return color_dict[color_choice]*bet_choice*34 - color_dict['black']*bet_choice - color_dict['red']*bet_choice
def colorchoose(msg):
while True:
try:
color = input(msg)
if color == 'r' or color == 'red':
return 'red'
elif color == 'b' or color == 'black':
return 'black'
elif color == 'g' or color == "green":
return 'green'
else:
print("Invalid Input")
except ValueError:
print("Invalid Input")
def betchoose(msg):
while True:
try:
bet = int(input(msg))
if bet >= 0 and bet <= bal:
return bet
elif bet > bal:
print("You don't have enough money!")
elif bet < 0:
print("You can't bet negative money!")
except ValueError:
print("Please enter a positive integer less than or equal to your balance")
def rollchoose(msg):
while True:
try:
rc = int(input(msg))
if rc*bet_choice <= bal and rc > 0:
return rc
elif rc*bet_choice > bal:
print(f"You cannot afford to roll rc times")
elif rc <= 0:
print("Please enter a positive integer")
except ValueError:
print("Please enter a positive integer")
def money_change_format(num,paren=False):
if num >= 0 and paren == True:
return '(+$%d)' % (num)
elif num < 0 and paren == True:
return '(-$%d)' % (-num)
elif num >= 0 and paren == False:
return '+$%d' % (num)
else:
return '-$%d' % (-num)
def replenish(msg):
while True:
try:
rep = distutils.util.strtobool(input(msg))
if rep == 0 or rep == 1:
return rep
else:
print('Please indicate whether you'd like to replenish your balance')
except ValueError:
print('Please indicate whether you'd like to replenish your balance')
print("Welcome to Roulette! Payouts are x2 for black and red and x35 for green. Your starting balance is $500n")
while not quit:
while bal > 0:
color_choice = colorchoose('What color would you like to bet on? ')
bet_choice = betchoose('How much money would you like to wager? ')
roll_choice = rollchoose('How many times would you like to roll? ')
old_bal = copy.copy(bal)
bal = bal + roll(roll_choice,bet_choice,color_choice)
print('New Balance: ','$'+str(bal),money_change_format(bal-old_bal,True))
rep = replenish("You're Broke! Would you like to replenish your $500 balance? ")
if rep: bal+=500; print('New Balance: $500 (+$500)')
elif not rep: quit = True
print('Play again anytime!')
```
python
$endgroup$
add a comment |
$begingroup$
I developed a simple command-line roulette game. Your only options are betting on color, but you can bet multiple times in one round
import copy
import distutils.core
from time import sleep
from random import randint
red_slots=(1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36)
black_slots=(2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35)
master_color_dict='red':0,'black':0,'green':0
quit = False
bal = 500
def roll(num,bet_choice,color_choice):
color_dict = master_color_dict.copy()
hits = 0
for _ in range(num):
sleep(.1)
r = randint(0,36); print(r,end=" ")
if r in red_slots:
color_dict['red']+=1
if color_choice == 'red':
hits+=1
print(' -- HIT x'+str(hits))
else:
print()
elif r in black_slots:
color_dict['black']+=1
if color_choice == 'black':
hits+=1
print(' -- HIT x'+str(hits))
else:
print()
elif r == 0:
color_dict['green']+=1
if color_choice == 'green':
hits+=1
print(' -- HIT x'+str(hits))
else:
print()
if color_choice == 'red':
return color_dict[color_choice]*bet_choice - color_dict['black']*bet_choice - color_dict['green']*bet_choice
elif color_choice == 'black':
return color_dict[color_choice]*bet_choice - color_dict['red']*bet_choice - color_dict['green']*bet_choice
elif color_choice == 'green':
return color_dict[color_choice]*bet_choice*34 - color_dict['black']*bet_choice - color_dict['red']*bet_choice
def colorchoose(msg):
while True:
try:
color = input(msg)
if color == 'r' or color == 'red':
return 'red'
elif color == 'b' or color == 'black':
return 'black'
elif color == 'g' or color == "green":
return 'green'
else:
print("Invalid Input")
except ValueError:
print("Invalid Input")
def betchoose(msg):
while True:
try:
bet = int(input(msg))
if bet >= 0 and bet <= bal:
return bet
elif bet > bal:
print("You don't have enough money!")
elif bet < 0:
print("You can't bet negative money!")
except ValueError:
print("Please enter a positive integer less than or equal to your balance")
def rollchoose(msg):
while True:
try:
rc = int(input(msg))
if rc*bet_choice <= bal and rc > 0:
return rc
elif rc*bet_choice > bal:
print(f"You cannot afford to roll rc times")
elif rc <= 0:
print("Please enter a positive integer")
except ValueError:
print("Please enter a positive integer")
def money_change_format(num,paren=False):
if num >= 0 and paren == True:
return '(+$%d)' % (num)
elif num < 0 and paren == True:
return '(-$%d)' % (-num)
elif num >= 0 and paren == False:
return '+$%d' % (num)
else:
return '-$%d' % (-num)
def replenish(msg):
while True:
try:
rep = distutils.util.strtobool(input(msg))
if rep == 0 or rep == 1:
return rep
else:
print('Please indicate whether you'd like to replenish your balance')
except ValueError:
print('Please indicate whether you'd like to replenish your balance')
print("Welcome to Roulette! Payouts are x2 for black and red and x35 for green. Your starting balance is $500n")
while not quit:
while bal > 0:
color_choice = colorchoose('What color would you like to bet on? ')
bet_choice = betchoose('How much money would you like to wager? ')
roll_choice = rollchoose('How many times would you like to roll? ')
old_bal = copy.copy(bal)
bal = bal + roll(roll_choice,bet_choice,color_choice)
print('New Balance: ','$'+str(bal),money_change_format(bal-old_bal,True))
rep = replenish("You're Broke! Would you like to replenish your $500 balance? ")
if rep: bal+=500; print('New Balance: $500 (+$500)')
elif not rep: quit = True
print('Play again anytime!')
```
python
$endgroup$
add a comment |
$begingroup$
I developed a simple command-line roulette game. Your only options are betting on color, but you can bet multiple times in one round
import copy
import distutils.core
from time import sleep
from random import randint
red_slots=(1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36)
black_slots=(2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35)
master_color_dict='red':0,'black':0,'green':0
quit = False
bal = 500
def roll(num,bet_choice,color_choice):
color_dict = master_color_dict.copy()
hits = 0
for _ in range(num):
sleep(.1)
r = randint(0,36); print(r,end=" ")
if r in red_slots:
color_dict['red']+=1
if color_choice == 'red':
hits+=1
print(' -- HIT x'+str(hits))
else:
print()
elif r in black_slots:
color_dict['black']+=1
if color_choice == 'black':
hits+=1
print(' -- HIT x'+str(hits))
else:
print()
elif r == 0:
color_dict['green']+=1
if color_choice == 'green':
hits+=1
print(' -- HIT x'+str(hits))
else:
print()
if color_choice == 'red':
return color_dict[color_choice]*bet_choice - color_dict['black']*bet_choice - color_dict['green']*bet_choice
elif color_choice == 'black':
return color_dict[color_choice]*bet_choice - color_dict['red']*bet_choice - color_dict['green']*bet_choice
elif color_choice == 'green':
return color_dict[color_choice]*bet_choice*34 - color_dict['black']*bet_choice - color_dict['red']*bet_choice
def colorchoose(msg):
while True:
try:
color = input(msg)
if color == 'r' or color == 'red':
return 'red'
elif color == 'b' or color == 'black':
return 'black'
elif color == 'g' or color == "green":
return 'green'
else:
print("Invalid Input")
except ValueError:
print("Invalid Input")
def betchoose(msg):
while True:
try:
bet = int(input(msg))
if bet >= 0 and bet <= bal:
return bet
elif bet > bal:
print("You don't have enough money!")
elif bet < 0:
print("You can't bet negative money!")
except ValueError:
print("Please enter a positive integer less than or equal to your balance")
def rollchoose(msg):
while True:
try:
rc = int(input(msg))
if rc*bet_choice <= bal and rc > 0:
return rc
elif rc*bet_choice > bal:
print(f"You cannot afford to roll rc times")
elif rc <= 0:
print("Please enter a positive integer")
except ValueError:
print("Please enter a positive integer")
def money_change_format(num,paren=False):
if num >= 0 and paren == True:
return '(+$%d)' % (num)
elif num < 0 and paren == True:
return '(-$%d)' % (-num)
elif num >= 0 and paren == False:
return '+$%d' % (num)
else:
return '-$%d' % (-num)
def replenish(msg):
while True:
try:
rep = distutils.util.strtobool(input(msg))
if rep == 0 or rep == 1:
return rep
else:
print('Please indicate whether you'd like to replenish your balance')
except ValueError:
print('Please indicate whether you'd like to replenish your balance')
print("Welcome to Roulette! Payouts are x2 for black and red and x35 for green. Your starting balance is $500n")
while not quit:
while bal > 0:
color_choice = colorchoose('What color would you like to bet on? ')
bet_choice = betchoose('How much money would you like to wager? ')
roll_choice = rollchoose('How many times would you like to roll? ')
old_bal = copy.copy(bal)
bal = bal + roll(roll_choice,bet_choice,color_choice)
print('New Balance: ','$'+str(bal),money_change_format(bal-old_bal,True))
rep = replenish("You're Broke! Would you like to replenish your $500 balance? ")
if rep: bal+=500; print('New Balance: $500 (+$500)')
elif not rep: quit = True
print('Play again anytime!')
```
python
$endgroup$
I developed a simple command-line roulette game. Your only options are betting on color, but you can bet multiple times in one round
import copy
import distutils.core
from time import sleep
from random import randint
red_slots=(1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36)
black_slots=(2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35)
master_color_dict='red':0,'black':0,'green':0
quit = False
bal = 500
def roll(num,bet_choice,color_choice):
color_dict = master_color_dict.copy()
hits = 0
for _ in range(num):
sleep(.1)
r = randint(0,36); print(r,end=" ")
if r in red_slots:
color_dict['red']+=1
if color_choice == 'red':
hits+=1
print(' -- HIT x'+str(hits))
else:
print()
elif r in black_slots:
color_dict['black']+=1
if color_choice == 'black':
hits+=1
print(' -- HIT x'+str(hits))
else:
print()
elif r == 0:
color_dict['green']+=1
if color_choice == 'green':
hits+=1
print(' -- HIT x'+str(hits))
else:
print()
if color_choice == 'red':
return color_dict[color_choice]*bet_choice - color_dict['black']*bet_choice - color_dict['green']*bet_choice
elif color_choice == 'black':
return color_dict[color_choice]*bet_choice - color_dict['red']*bet_choice - color_dict['green']*bet_choice
elif color_choice == 'green':
return color_dict[color_choice]*bet_choice*34 - color_dict['black']*bet_choice - color_dict['red']*bet_choice
def colorchoose(msg):
while True:
try:
color = input(msg)
if color == 'r' or color == 'red':
return 'red'
elif color == 'b' or color == 'black':
return 'black'
elif color == 'g' or color == "green":
return 'green'
else:
print("Invalid Input")
except ValueError:
print("Invalid Input")
def betchoose(msg):
while True:
try:
bet = int(input(msg))
if bet >= 0 and bet <= bal:
return bet
elif bet > bal:
print("You don't have enough money!")
elif bet < 0:
print("You can't bet negative money!")
except ValueError:
print("Please enter a positive integer less than or equal to your balance")
def rollchoose(msg):
while True:
try:
rc = int(input(msg))
if rc*bet_choice <= bal and rc > 0:
return rc
elif rc*bet_choice > bal:
print(f"You cannot afford to roll rc times")
elif rc <= 0:
print("Please enter a positive integer")
except ValueError:
print("Please enter a positive integer")
def money_change_format(num,paren=False):
if num >= 0 and paren == True:
return '(+$%d)' % (num)
elif num < 0 and paren == True:
return '(-$%d)' % (-num)
elif num >= 0 and paren == False:
return '+$%d' % (num)
else:
return '-$%d' % (-num)
def replenish(msg):
while True:
try:
rep = distutils.util.strtobool(input(msg))
if rep == 0 or rep == 1:
return rep
else:
print('Please indicate whether you'd like to replenish your balance')
except ValueError:
print('Please indicate whether you'd like to replenish your balance')
print("Welcome to Roulette! Payouts are x2 for black and red and x35 for green. Your starting balance is $500n")
while not quit:
while bal > 0:
color_choice = colorchoose('What color would you like to bet on? ')
bet_choice = betchoose('How much money would you like to wager? ')
roll_choice = rollchoose('How many times would you like to roll? ')
old_bal = copy.copy(bal)
bal = bal + roll(roll_choice,bet_choice,color_choice)
print('New Balance: ','$'+str(bal),money_change_format(bal-old_bal,True))
rep = replenish("You're Broke! Would you like to replenish your $500 balance? ")
if rep: bal+=500; print('New Balance: $500 (+$500)')
elif not rep: quit = True
print('Play again anytime!')
```
python
python
asked 3 mins ago
alec_aalec_a
1976
1976
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217589%2fsimple-command-line-roulette-game%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217589%2fsimple-command-line-roulette-game%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown