Games of Chance project (Roulette section)

Right now the function I wrote can only check if the user guessed even or odd and return that much money. How do I incorporate the other rules for roulette and allow the player to guess a number as well as even or odd? I’m also not sure how to put “0” and “00” into the function like it says to.
The roulette function is task number 6.

def roulette(guess, bet):
  global money
  x = random.randint(1,36)
  if x % 2 == 0:
    spin = "even"
  elif x % 2 == 1:
    spin = "odd"
  if guess == spin:
    result = "won"
    money += bet
    result = "lost"
    money -= bet

    "You spun a %s. You guessed %s. You %s and now have $%.2f" %(x, guess, result, money )

For 0 and 00, consider that they are slots that the ball can fall into. It just means that your list you consider is that much bigger. You would have to decide how to index it. One possible way:

00: index-0
0: index-1
1: index-2
2: index-3
1 Like


0: index-0
1: index-1
2: index-2
00: index-37 # ( [-1] )


1 Like

Haha that would be the human way. :slight_smile:
@mtf bread loaves don’t always think like this.


Furthermore, a dictionary would be handy for custom ordering of the colors (not all odd are black), so each slot label would be its own key. The order is not sequential, either. A dictionary can be ordered and frozen after customization, but wouldn’t need to be if we throw in an index key:value according to position around the wheel.

This is how I (incorrectly, as determined later) created my wheel…

wheel = dict(zip([*map(str, range(37))]+['00'], cycle((('Even', 'Red'), ('Odd', 'Black')))))

cycle has to be imported from itertools. The issue though is the consistent color distribution.

1 Like

Here is the test code (I never took it any further)…

def get_spin():
  return spin([*wheel.keys()])

spin is an alias of choice imported from random.

print (wheel.get('39', False))
print (wheel.get('00', False))
print (get_spin())
a = get_spin()
b, c = wheel.get(a, False)
print (a, b, c)
('Odd', 'Black')
14 Even Red

Thanks for all the replies. I haven’t learned about making dictionaries or how to index things yet in the computer science course so I’ll have to do that first.