Simple command-line roulette game Announcing the arrival of Valued Associate #679: Cesar...

Can a non-EU citizen traveling with me come with me through the EU passport line?

Fundamental Solution of the Pell Equation

Why am I getting the error "non-boolean type specified in a context where a condition is expected" for this request?

2001: A Space Odyssey's use of the song "Daisy Bell" (Bicycle Built for Two); life imitates art or vice-versa?

Can I cast Passwall to drop an enemy into a 20-foot pit?

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

How can I make names more distinctive without making them longer?

What does an IRS interview request entail when called in to verify expenses for a sole proprietor small business?

Can an alien society believe that their star system is the universe?

Check which numbers satisfy the condition [A*B*C = A! + B! + C!]

Is the Standard Deduction better than Itemized when both are the same amount?

How to run gsettings for another user Ubuntu 18.04.2 LTS

Should I discuss the type of campaign with my players?

Short Story with Cinderella as a Voo-doo Witch

Echoing a tail command produces unexpected output?

What would be the ideal power source for a cybernetic eye?

If a contract sometimes uses the wrong name, is it still valid?

How come Sam didn't become Lord of Horn Hill?

Storing hydrofluoric acid before the invention of plastics

String `!23` is replaced with `docker` in command line

Sci-Fi book where patients in a coma ward all live in a subconscious world linked together

Dating a Former Employee

Generate an RGB colour grid

prime numbers and expressing non-prime numbers



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)





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







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!')

```








share









$endgroup$



















    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!')

    ```








    share









    $endgroup$















      0












      0








      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!')

      ```








      share









      $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





      share












      share










      share



      share










      asked 1 min ago









      alec_aalec_a

      1976




      1976






















          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
          });


          }
          });














          draft saved

          draft discarded


















          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
















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

          How do i solve the “ No module named 'mlxtend' ” issue on Jupyter?

          Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...