This section continues to refine the second section of the digital mini-game:
1) Continue to use the Conditional branch statement, to improve the user guessing the wrong number, give hints, is guessed big or small;
2) Use loop statements (while loops) to enable users to guess numbers and improve user experience without exiting the game;
3) Introducing foreign aid (import), importing external modules to achieve more powerful functions, here is the use of random number modules for the random.
Here's the code for the game:
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/88/57/wKioL1fx1l_S8xH7AABuNp9LW_0120.png-wh_500x0-wm_3 -wmp_4-s_2313907669.png "title=" Gamefinal.png "alt=" Wkiol1fx1l_s8xh7aabunp9lw_0120.png-wh_50 "/>
Knowledge points to note in this section:
1, the syntax of Python is a colon and indentation, if the branch structure and the condition statement of the while loop structure must have:, Python in the command block through indentation implementation, the same indentation level is the same command block, without the use of parentheses and so on.
There are no punctuation marks at the end of the other statements, and of course you have no grammatical errors at the end of the quotation marks (;), but we are accustomed to not adding any punctuation.
2, the introduction of external modules using the Import keyword implementation, if not introduced in advance, and directly use the contents of the module, will error, the hint is not defined in advance
3. The Randint () of the random module returns a random integer with a syntax of Randint (A, A, a B), the start and end points of the generated random integers, and a random integer containing A and B.
This article is from the "Davidlee's Linux Road" blog, so be sure to keep this source http://davidlinux.blog.51cto.com/5965954/1858535
Python Basic Learning Notes (V)