Python: Getting started with zero basics. I learned the book "Android-the first line of code" in the winter vacation. I plan to learn the Python language this winter vacation, on the one hand, it is more interested in python crawlers, and on the other hand it is also a tool for searching. This study did not find a suitable book for getting started with zero basics, so I directly watched the python video of the little turtle series and felt that the effect was good. Let's talk less and go straight to the topic.
I have learned a bit about python (although I have learned a little about it). I have learned C, C ++, Java, and other languages before, some syntax structures can be said to be deep-rooted, but python is really not unusual. the syntax structure is a lot worse than the above language. it is really awkward for me. For example, python does not need to declare a variable and can be used directly if it is used. In addition, python does not use {} to define the scope of a function or statement. Instead, it uses indentation. the same indentation has one scope in the following table. There are many other scopes that will be added later. In short, it also needs to be adapted for a period of time.
First, you can use a simple number-guessing game to learn python's if and while statements.
# Compile a guess number game. The function requires multiple guesses. The number is randomly generated. # if the given number is not the correct answer, give the corresponding prompt. Import randomprint ("---------- welcome to my guess digital game !!! --------- ") Print (" ---------- you only have three chances. Be sure to cheer up --------- ") secret = random. randint () temp = input ("Enter the number you want to guess:") guess = int (temp) flag = 3if (guess = secret) and (flag = 3): print ("Brother, you are really good. you guessed it all at once") else: while (guess! = Secret) and (flag! = 1): flag = flag-1 if guess
Secret: print ("The number you guessed is big, it's big") flagtostr = str (flag) print ("You still have" + flagtostr + "") temp = input ("Please enter your number again:") guess = int (temp) if secret = guess: print ("Brother, you finally guessed it !!! ") Else: print (" Sorry, the opportunity is used up !!! ") Secrettostr = str (secret) print (" The correct answer is "+ secrettostr) print (" Thank you for playing my games !!! ")
Program running:
The previous mini-games mainly familiarize themselves with the python syntax structure, understand how python controls the statement scope through indentation, and use built-in functions such as input and print, python built-in functions will be added later.
The above is the content for getting started with Python. For more information, see PHP Chinese website (www.php1.cn )!