Punto Banco - dealing cards - 3
We are going to set up a data structure in Python called a list. This will hold all the cards that could be drawn.
Because the suit of a card is unimportant in Punto Banco, we just need to hold the values of each of the cards. In addition, although there are 52 cards in a pack of cards, in a casino, they typically shuffle together and use four to six packs of cards in a 'shoe', as shown in the picture. This means that you can't actually ever run out of a particular card. All we need to do is to hold the values from Ace through to King once, and then randomly pick from that list each time we need a card. To do that, we will need to import and use Python's random module.
We have used the Python random module before. You may want to look up the documentation for it. Google 'Python random module' to find the details.
Q1. Type this code in and get it working.
Notice the backslash \ after card "6" in the list. It's a very useful way of breaking up really long lines in Python. You can't just go on another line because Python will think it's a new instruction. The backslash tells Python that the next line is part of the current line. People always get the backslash \ confused with the forward slash /. One way to remember which is which is that the backslash leans backwards whilst the forward slash leans forwards.
It's also worth noting that we are storing strings in the list. Python actually lets you store a mixture of data types in lists but it makes life a little easier if we just use one data type. Since we want to store words like Ace, it makes sense to store all the data as strings. This is important, because the string 5 is not the same as the number 5. The string 5 is not an amount of something, in the same way that a telephone number is not an amount of something. It's a code. If we want to use the string 5 as an amount, we must remember to convert it into an integer.
Try running the code a few times. Does it look random? It can get a bit tedious having to run the code each time to pick one card. It would be better to add some code to print 20 cards randomly, just so you can see everything seems to be fine. This isn't part of the program, but it is always a good idea to do a little bit at a time and the do some testing.
Q2. Add some extra code, like this:
Q3. Try changing the code so it prints 100 random cards, or a thousand. does it look random?