People come to "Python" in different ways: someone is interested in AI, someone begins to study web development on "Python" in return for the already annoying PHP; I did it differently - I began to notice that this language is used quite often in modern programming not only among enthusiasts, but also among large companies. In general, the language is gaining popularity among the masses, so I decided to “take a closer look” at it, well, that is, study it.
Studying a new algorithmic language, not to say that the process is very fascinating, if you are already familiar with several ... You can choose a book, you can use some online course, or you can even use "roller-cartoons" and ... "sit-read-learn" . - Boredom!
I scored on the web on the “Python” tutorial book, in principle, not bad, but not to say that it pretends to complete the syntax and stumbled on “Examples of programs” there. Among several others, there was one very curious example there that literally “turned back the clock”, and I found myself in those times when “the trees were bigger and the grass is greener” ... His name: “We write blackjack”.
')
It all started with computer games, when instead of using a “convex-screen TV” “as intended”, he managed to “zayuzat” as a monitor to all kinds of “ZX spectrum” and other “corvettes”, and in computer science lessons, instead of programming, young shoots Moreover, I tried to run some “races” or a space “shooter” from a teacher’s computer, uploading it to all the students in a semblance of a local network.
And in the quiet of the laboratory of any chemistry room, some EU computer would nest, in which more adult comrades launched Prince of Persia or, oh, the coolest game of all times and peoples, Metal mutant! Yes, there were times ... And then everyone was covered with a wave of "Dandy" and "Segi".


Yes, it was a lyrical digression to clarify that children are very greedy for all sorts of games. Therefore, a very good move is to teach them programming using the example of writing a game. At one time in high school, I wrote a space shooter for Turbo Pascal, while the “great and terrible” C ++ was just beginning to enter the curriculum for students and only Assembler was ahead of it in its coolness.
And then I turned up such an opportunity to ponastically nagging ... In general, I downloaded the source in “Anaconda” and began to study (maybe someone prefers IDLE, but I like “Anaconda” for a variety of tools). So, here we have ... Well, it seems nothing complicated. Let's check the performance of the code. - Works.
koloda = [6,7,8,9,10,2,3,4,11] * 4 import random random.shuffle(koloda) print(' ?') count = 0 while True: choice = input(' ? y/n\n') if choice == 'y': current = koloda.pop() print(' %d' %current) count += current if count > 21: print(', ') break elif count == 21: print(', 21!') break else: print(' %d .' %count) elif choice == 'n': print(' %d .' %count) break print(' !')
It works, it works ... But I just do not like this game. And where are the statistics, that played one round - and the new? - No, that is not good! I quickly began to edit the code, removing unnecessary "brecks", adding a cycle and counters of victories and defeats. Well, that's better. Oh yeah, there are only four decks in the game and they will quickly end if you sit down and begin to actively “spire”. Then let there be a thousand, no - ten thousand! This amount should be enough until the program ends and says “Sorry, friend, -Error”.
import random koloda = [6,7,8,9,10,2,3,4,11] * 10000 random.shuffle(koloda) count = 0 looses = 0 wins = 0 while True: if count == 0 : print("------------") print(" !") print("------------") choice = input(' ? y/n\n') if choice == 'y': current = koloda.pop() print("") print(' %d.' %current) count += current if count > 21: print(' %d .\n' %count) print(', . :-(\n') elif count == 21: print(', 21!\n') else: print(' %d .' %count) if count >= 21: if count == 21: wins = wins + 1 if count > 21: looses = looses + 1 print(": %d ," %wins, " %d .\n" %looses) count = 0 elif choice == 'n': print(": %d ," %wins, " %d .\n" %looses) break print(' !')

Yes, everything is great ... But I don’t like to run this program from under the interpreter, and if I’m a regular user and don’t want to set myself these “Pythons” ?! - Come on, I say! Well, and this grief to help ... And suddenly, from somewhere, Fedya took it, who said his word:

- Shurik, but maybe not necessary?
- You must Fedya, you must!
But about this in the second part.