First, what is user interaction
User interaction is where the application can receive the user's external input and use the input data as a parameter for subsequent running of the program.
Second, why should have user interaction
For example, a person to the bank to withdraw money, he and the teller said how much money to withdraw, the teller will give him the corresponding money, and his account under the amount of the deposit to reduce the corresponding value. This process to let the computer instead of the first computer needs to know whether the person to take the money is not himself, and then need to know how much money this person needs to do, this time need user interaction to achieve, the first person to enter the account password to the computer to determine whether to take the money is not himself, after the verification through the person to enter the amount The computer will give him the appropriate money and then reduce the amount of the deposit under his account.
Third, how to realize user interaction
Python3 receives user input through the input function, and all data entered by the user is saved as a string type, and when using the input function we can add a hint in parentheses to indicate what information the user should enter, such as Name=input (' Please enter username ')
There are two functions in python2 to implement user interaction, one is raw_input () and the other is input (). The usage of raw_input () is the same as the input () function of Python3, and the input () function of Python2 is not the same as the input () function of Python3, and the input () function of Python2 is called Raw_input ( function and then call the eval () function, so you can even pass an expression to it, and the input function will return the result to you, and the official recommendation is to use Raw_input () to receive the external input in python2 generally.
Iv. notes
The role of annotations in programming is to increase the readability of the code, making it easier for others to read the code we write, and to help us recall the intent to write this code when we have written the code for a long time and then review it. After all, after writing tens of thousands of lines of code for a long time, it is normal to forget the intention of writing this code.
The symbols commonly used for annotations in Python are # and ' ', #号一般用于注释单行代码写在要注释的代码最左边, and three-line annotations are generally used to interpret blocks of code, such as
# while True:
# Msg=input (' msg: ')
# If Msg.startswith (' Alex '):
# msg=msg + ' _SB '
# Print (msg)
Above is the use of the # notation
def subclass_exception(name, parents, module, attached_to=None): """ Create exception subclass. Used by ModelBase below. If ‘attached_to‘ is supplied, the exception will be created in a way that allows it to be pickled, assuming the returned exception class will be added as an attribute to the ‘attached_to‘ class. """ class_dict = {‘__module__‘: module}
The use of three quotes as above, to explain the role of a piece of code
Python-based user interaction and annotations