Python Basic Learning Notes (V)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.