# 2016-5-12

Source: Internet
Author: User

Rules for variable definitions:

• Variable names can only be any combination of letters, numbers, or underscores
• The first character of a variable name cannot be a number
• The following keywords cannot be declared as variable names
[' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' F ' Rom ', ' Global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' try ', ' while ', ' WI Th ', ' yield ']

Example

#!/usr/bin/env python This is where Python is declared, and Env says that if the location on Linux is changed, you can find
#-*-coding-utf-8-*-UTF-8, is the compression and optimization of Unicode encoding, he no longer uses a minimum of 2 bytes, but to classify all characters and symbols
# using while loop input 1 2 3 4 9 10

A=0
While True:
A=a+1 This step is mainly thought, 1, 2, 3,4 actually used the mathematical thinking, on the difference 1
Print (a)
If a==10: Note that python equals use = =
Break when a=10, jump out of the loop

#!/usr/bin/env python
#--coding-utf-8--

# All the odd numbers in the output 1-100
A=0
While True:
A=a+1
d=a%2 the arithmetic of the numbers used here Plus + minus-multiply * divide/remainder with a remainder of 1 is an odd remainder of 0 is an even number

If d==1:
Print (a)
If a==100:
Break

#!/usr/bin/env python
#--coding-utf-8--
#求1-100 of all the numbers and to find out that the number within 100 is very simple, how to use the number of each output as the first, before and after adding, thought is very heavy
A=0
B=0
While True:
A=a+1 can show the number 100.
B=a+b this is a key. B is equivalent to paying the data taken out every time to B, in b=0, causing B to also follow a change in a, and always equal to the last digit 3=1+ (+) A=1 thought
If a==100:
Break
Print (b) is also important to be in the same column as while, indicating that the value of B is printed when jumping out of the loop

#/user/bin env python
#-coding=utf-8
#求1 -2+3-4+5 of all the numbers and the ability of the first few to assemble
A=0
B=0
While True:
If a==100:
Break
A=a+1
d=a%2
If d==0:
B=b-a
If d==1:
B=b+a
Print (b)

While loop

A!=number (A is not equal to number) in the case of a loop with a while True opposite

Characteristics:

1, when the input is correct can jump out of the cycle, you can add the counter to use to limit the number of times

2, input correct can join the hint

3, note: The use of Pycharm can save a lot of trouble, there will be hints.

Counter

In the counter, in cases where the number of times is less than 3

1, can be judged

2. The counter must be placed in the same column as the If, and remain at the end of the decision.

3, break is to jump out of this cycle, directly out of the else, the bottom print

4. The second else is a hint in the case of a (loss error). (You will be locked out)

For loop

1, b represents the variable

2016-5-12

Related Keywords:

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.