Python entry-level classical Python programming oriented to solving computing problems needs to be improved

Source: Internet
Author: User

1.4.2: python divides the code into two types: Expressions and statements.
Expressions and statements ::
Expression (the combination of values and operators produces a new value -- return value. If you enter an expression in python shell, the returned value is displayed. That is to say, if the value of x is 2, the value of the expression x + 5 will be 7)
Statement. Statements can execute various tasks. Some statements may set program control statements, while some statements may require some resources. Statement running results may have side effects. The side effect is some changes that occur during statement execution. For example, if myint = 5, this statement does not return a value, but does set the value of myint to 5)

1.7.5: enhanced value assignment operator: shortcut
Myint + = 2 is equivalent to myint = myint + 2
Myint-= 2 is equivalent to myint = myint-2
Myint * = 2 is equivalent to myint = myint * 2
Myint/= 2 is equivalent to myint = myint/2
(Programming skills: Be careful when using the enhanced value assignment statement. The left side of the assignment number must be the variable associated with a value. Variables cannot be defined using an enhanced value assignment statement. If there is no myint, what does myint = myint-2 mean ?)

1.9: develop algorithms:
Algorithm: A method (composed of a series of steps) describes how to solve a problem or a class of problems.
The person who solves the problem records what needs to be done to solve the problem, which is called the description of the algorithm. Descriptions can be divided into English, charts, flowcharts, or any tool that can be used to describe. After finding the best solution to your problem, you can convert the algorithm into code that implements the algorithm.

The working principle of the while loop:
The program enters the while structure and determines the value of the Boolean expression.
If the value of the Boolean expression is true, the corresponding while LOOP body is executed.
After the loop body is executed, the control statement returns to the position of the Boolean expression and is re-determined.
If the value of the Boolean expression is true, it is executed once in a loop. If the value of a Boolean expression is false, skip the loop body and run the code after the while loop.

While is equivalent to:
You can write a program to run a while loop like a for loop. However, not every while loop can be expressed as a for loop. For example:
For I in range (5 ):
Print I

I = 0
While I <5:
Print I
I + = 1
The for statement is easier to read and understand, but it only moves between elements of an object through the iterator. Fortunately, in python, there are many objects with iterators, so in general, you can use the for loop.

Algorithm:
The algorithm describes how to solve the problem.
Programs implement algorithms in specific languages on specific computers.
The algorithm must provide the input and output descriptions. That is to say, the output is generated based on this input.
If the algorithm is an idealized computing process, the program is the ideal implementation process. The algorithm abstracts the problem solution. In this sense, the program is the actual solution. Therefore, the program has different features (readability/) from the algorithm /)

Code readability: hard-to-read code is difficult to get help or advice from others. In addition, such code is unlikely to be safe. A Brief History of computing emphasizes this point of view, not to mention reading it for others... (a comment, a good name (program name variable name) is very helpful)
Essence:
1. required input
2. How to test whether the input meets the requirements?
3. What is the expected or required output for each input?
4 which output tests are appropriate?
5 As mentioned above, there are other things ???


Isdigit () function

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.