Python base language and IF/WHILE statement structure

Source: Internet
Author: User

The next step is to learn the variables: replace complex strings with simple variables

the first letter of the variable cannot be a number or a special symbol ~! @#¥ and so on.

Development of character Sets:

ASCII 255a1an account1bytes------>1980yearsGB2312Support7thousand Men--------->1995years,GBK10, Support2Wmany men------>2000years,GB18030Support27000Many men,-----Unicode,Man accounted for2bytes, but English is not good to store------->utf8,1an English account1bytes,1a man accounted for3of bytes

Example One: ( compiled and run in Pycharm, followed by the same code)

Method One:

Name=input ("Name:")

Age=input ("Age:")

Job=input ("Job:")

Salary=input ("Salary:")

Info= ""

------Info of%---------

name:%

age:%

job:%

salary:%

"% (name,name,age,job,salary)

Print (info)

Method Two:

Name=input ("Name:")

Age=input ("Age:")

Job=input ("Job:")

Salary=input ("Salary:")

Info= ""

------info of {_name}--------

Name:{_name}

Age:{_age}

Job:{_job}

Salary:{_salary}

". Format (_name=name,_name=name,_age=age,_job=job,_salary=salary)

Print (info)

The following is the proofreading of the account password:

_username= ' Xiangxiao ' #(the default value is in single quotes)

_password= ' abc123 '

Username=input ("Username:")

Password=input ("passwoed:")

If _username==username and _password==password:

Print ("Welcome {name} come here ...". Format (name=username))

else:

Print ("Failed password or username")

Note : When compiling in Pycharm, pay attention to the first line indent,indentationerror to indicate indentation error

Circular precautions:

Break: ends the current loop

Continue: end this cycle and proceed directly to the next cycle

Example two: Guess the age, to achieve the actual age, ask to guess three age, more than three times, then exit the cycle;

oldboy_age_of=56

Count=0

While count<3:

Guess_age=int (Input ("Guess_age:"))

If Guess_age==oldboy_of_age:

Print ("You is Right")

Elif Guess_age<oldboy_of_age:

Print ("Please guess bigger")

else:

Print ("Please guess smaller")

If count==3:

Guess_confirm=input ("Does want to guess it?")

If guess_confirm! = ' n '

Count=0

Else

Print ("You have tried too much ...")

Python base language and IF/WHILE statement structure

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.