Can someone explain Roulette?(Games of Chance)

https://www.codecademy.com/practice/projects/games-of-chance
I researched it and am still totally lost. Anyone here know how to play it?

The roulette wheel has 38 standard places, for our purposes. The numbers 1 thru 36 sandwiched between ‘0’ and ‘00’. Half the spaces are red, the others, black, alternating. 0 is ‘Even’ and 00 is ‘Odd’.

1 Like

Players try to guess which of the above slots a small ball will land in when it is rolled around the wheel. It is usualy acompanied with gambling against a banker.

1 Like

To give yourself a goal to work towards, think of how we would get this to display in console…

27 ('Odd', 'Black')
2 Likes

When your guessing numbers, can you guess 0 and 00?

No, because there is no such number as 00. We need to use strings (or that is one approach). One supposes we could check if the number is 38 and treat it as the 00. Only problem is 38 is even, and 00 is odd (so 37 would be 00 and 38 would be 0). I just went with the strings.

Right here, I’m assuming we guessed the number 27, and 27 is Odd and Black.
How would you determine whether you lost or not using this?

That would be the outcome of a spin (our first goal). We would still need to check it against our wager. Did we bet on the number, the parity, or the color?

1 Like

I’ve been thinking and all I can think of is making a dictionary and individual key:value pairs for each number. But that’s not practical. I’m stuck.

Careful, there. What makes it impractical?

Well, I thought you should avoid having to type everything yourself. That’s what makes it impractical.

We’re programmers. Automate.

Question, can I make a key’s value the output of a function?

If those values are strings that match our needs, why not?

1 Like

Wait I think I got it! Now how can I make it so the output is num ('parity', 'color') instead of num: ('parity', 'color')

Don’t print the dict object directly. The spin returns a key. The value is the get() of that key.

a = get_spin()
print (a, _.get(a))

where _ is the name of your dictionary.

What are you doing here?

We have a dictionary, so that means we can extract a list of the keys. That list becomes our argument in the random.choice() method.

return random.choice(list(_.keys()))
1 Like

Hey if you’re still there! I actually discovered another way to do it.

spin_list = []
for num in nums:
   spin_list.append(f'{num} {even_or_odd(num), red_or_black(num)}')       
spin = random.choice(spin_list)

Not completely sure why this {even_or_odd(num), red_or_black(num)} automatically has parenthesis around it.

Then you’re stuck parsing the string for the data. Not my favorite approach.

{
    '0': ('Even', 'Red'),
    ...
}

That’s the structure I used to get the print out, above.

a = get_spin()
b, c = _.get(a)
print (a, b, c)    #  34 Even Red