Python 0 Basic Primer One

Source: Internet
Author: User
Last winter Vacation study "android-first line Code" this book, this winter vacation intends to learn the language of Python, on the one hand because of the Python crawler is more interested in, on the other hand is a search for a tool. This study because did not find a more appropriate 0 basic primer books, so directly look at the small turtle series of Python video, feeling the effect is good. Gossip less, goes straight to the subject.
First of all, to learn the Python language to give me the feeling (although the knowledge learned a little), because before the C, C + +, Java and other languages, to some grammatical structure can be said to be deeply rooted, and python is really not go the ordinary way, grammatical structure root of the above language poor many, I really feel very awkward. Python, for example, does not have to declare a variable and use it directly. There is Python does not use {} to define a function or the scope of the statement, but the use of indentation, the same indentation of the following table one by one scope, there are many, will slowly add, in short, also need to adapt to a period of time.
First, use a simple game of guessing numbers to learn about Python's if statement, while statement, and so on.

#编写一个猜数字的游戏, the function requires the realization of multiple guesses, the number randomly generated # if the number given is not the correct answer, and give the corresponding hint. Import Randomprint ("----------Welcome to play my guess number game!!!" ---------") Print ("----------You only have 3 chances, be sure to refuel Oh---------") secret=random.randint (1,10) temp=input (" Please enter the number you want to guess: ") guess= Int (temp) flag=3if (Guess==secret) and (flag==3):     print ("Brother, you're awesome, you guessed right at once") Else: While     (Guess!=secret) and (flag !=1):          flag=flag-1          if Guess<secret:               print ("You guessed the number is small, small")          if Guess>secret:               print ("You guessed the number is big , "Flagtostr=str")          print ("You have +flagtostr+")          temp=input ("Please reenter your number:")          Guess=int ( Temp)     if secret==guess:          print ("brother, you finally guessed it!!!" ")     Else:          print (" I'm sorry, the opportunity is exhausted!!! ") SECRETTOSTR=STR (          secret) print (          "correct answer for" +secrettostr) print ("Thank you for playing my little game!!!") ")

Program run:

The above small game is mainly familiar with the syntax structure of Python, understand Python by indenting the scope of the control statement, as well as input, print and other built-in functions, Python's built-in functions will be slowly added later.

The above is the basic introduction of Python 0, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.