first Python code

My first Python code

I’m currently learning how to program at school and have just finished writing my first Python code.  The game that I’ve made took me a few weeks to write. I am so stoked to be done with it! I enjoyed programming way more than I thought I would and can’t wait to learn more about it.

Because programming is something that I would like to get better at, I thought it would be nice to post my progress here on my blog.

Here is the code.

Bulgarisk Patiens – the instructions:

The game is in Swedish. It’s called: “Bulgarisk Patiens”. These were the instructions (also in Swedish).

In short, the user is first allowed to choose an amount of cards between 2 and 52. This amount is then divided into different stacks, randomly. If the user, for example, chose to play with 10 cards, the stacks could look like this: [4, 4, 2].
3 stacks with 4 cards in the first one, 4 in the second and 2 in the third. The value of the cards isn’t important in this game.

When that is done, a card is then taken from each stack and a new stack is created with these cards. Using the same example as before, the next step of the game would look like this: [3, 3, 1, 3].

The process is repeated until stabilty, called “patiens”, is reached. For example:
(I’ve sorted each list in the order of magnitude)
[2, 2, 2, 4]
[1, 1, 1, 3, 4]
[2, 3, 5]
[1, 2, 3, 4]
[1, 2, 3, 4]
[1, 2, 3, 4]

The game is now over. The process can be repeated indefinetly and the stacks would always end up looking the same: [1, 2, 3, 4].

If “patiens” isn’t reached within 25 steps, the game stops. It also stops when it finds a “cycle”. For example:
[2, 3]
[1, 2, 2]
[1, 1, 3]
[2, 3]
… etc

Second part of the game:

The second option that the user has when playing the game is getting to look at statistics for it. He can choose the amount of games that he wants the computer to play and then gets to see how many times stability has been reached in those games. For example, if the user chooses 5 games, he could see:
“3 games reached ‘patiens’ and 2 didn’t.”

The final instruction that I had was to create a GUI (Grafical User Interface) for the game. Learning how to do this took a bit of time for me but it’s super fun to be able to actually click on buttons and see things happen when playing my game. All in all, I’m so happy to have finished writing the code and I can’t wait to write my next one.


Leave a Reply