Python Learning Series (chapter II): Use of the basic syntax of Python

Source: Internet
Author: User

One: Python user input:

1.1 Python input

#!/usr/bin/env python#-*-coding:utf-8-*-# author:flyfish#import getpass_username = "Zhangyy" _password = "abc123" Usern AME = input ("username:") password = input ("Password:") # # # password = getpass.getpass ("Password:") if _username = = Usernam E and _password = = Password:print ("welcom user {name} login". Format (Name=username)) else:print ("Invalid username or Password ")

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/9A/27/wKiom1lSFILSz8euAAB2JtwHSnE758.png-wh_500x0-wm_ 3-wmp_4-s_1481907517.png "title=" 333.png "alt=" Wkiom1lsfilsz8euaab2jtwhsne758.png-wh_50 "/>

Two: If....else cycle:

Set your age in the program, and then start the program to let the user guess, after the user input, according to his input prompts the user to enter the correct, if the error, the hint is guessed big or small


Comments:

Outer variables, which can be used by the inner layer code

Inner variables should not be used by the outer code

#!/usr/bin/env python#-*-coding:utf-8-*-# author:flyfishage_of_zhangyy = 26guess_age = Int (input ("Guess zhangyyy Age:" ) If Guess_age = = Age_of_zhangyy:print ("Yes,yo go It") elif guess_age > Age_of_zhangyy:print ("Think smaller ...") Else:print ("Think Bigger")

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M02/9A/28/wKiom1lSGTGCYPg3AAZNMOpz9po926.png-wh_500x0-wm_ 3-wmp_4-s_3417703591.png "title=" 444.png "alt=" Wkiom1lsgtgcypg3aaznmopz9po926.png-wh_50 "/>

Three: the While loop

#!/usr/bin/env python#-*-coding:utf-8-*-# author:flyfishcount = 0while true:print ("Count", count) Count = Count + 1

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M00/9A/29/wKioL1lSGcaQmQDOAALBuxWHaK8613.png-wh_500x0-wm_ 3-wmp_4-s_1512722140.png "title=" 5.png "alt=" Wkiol1lsgcaqmqdoaalbuxwhak8613.png-wh_50 "/>

#!/usr/bin/env python# -*- coding: utf-8 -*-#  author:flyfishage_of_zhangyy = 26count = 0while true:    if  count == 3:        break    guess_ Age = int (Input ("Guess zhangyyy age:"))     if guess_age ==  age_of_zhangyy:        print ("Yes,yo go it")          break    elif guess_age > age_ Of_zhangyy:          print ("Think smaller ...")      else:        print ("Think bigger")      count+=1 

650) this.width=650; "Src=" Https://s5.51cto.com/wyfs02/M00/9A/28/wKiom1lSGiugoX3pAAK4fm_C49Y652.png-wh_ 500x0-wm_3-wmp_4-s_1691709091.png "title=" 6.png "alt=" wkiom1lsgiugox3paak4fm_c49y652.png-wh_50 "/>

#!/usr/bin/env python# -*- coding: utf-8 -*-# author:flyfishage_of_zhangyy  = 26count = 0while count<3:    guess_age = int (Input (" Guess zhangyyy age: "))     if guess_age == age_of_zhangyy:         print ("Yes,yo go it")          break    elif guess_age > age_of_zhangyy:           print ("Think smaller ...")     else:         print ("Think bigger")     count+=1     if count ==3:        countine_confirm  = input ("do you want to guessing ....")          if countine_confiRm != ' n ':             count ==0else:     print ("You have tried too many times. Fuck off ")


650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/9A/28/wKiom1lSGufCIjKrAAOJa8UsP84766.png-wh_500x0-wm_ 3-wmp_4-s_331479539.png "title=" 7.png "alt=" Wkiom1lsgufcijkraaoja8usp84766.png-wh_50 "/>


Three: Python's module knowledge:

Python's strength is that he has a very rich and powerful standard library and third-party library, almost any function you want to implement has the corresponding Python library support, later in the course will be in depth to explain the various libraries commonly used, now, we first to symbolically learn 2 simple.







This article is from the "flyfish" blog, make sure to keep this source http://flyfish225.blog.51cto.com/3735447/1942437

Python Learning Series (chapter II): Use of the basic syntax of Python

Related Article

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.