Basic Structure of a Program

Input data into variables — Perform calculations based on the data — Output the results

Input Statements

In Python 3.x, the input statement is the input() function.
For example:

1
2
a = input()   # Wait for user input and assign it to a
b = input() # Wait for user input and assign it to b

In this expression, anything can be placed inside the parentheses. If you want to provide a text prompt, you need to enclose it in quotes.

input can accept any type of input, including numbers, letters, Chinese characters, symbols, and other strings.

For example:

1
2
x = 3000
a = input(x)
1
a = input('Please enter a number:')

The output of the first box is 3000. When running the program, it will first display 3000 and then wait for you to input.

The output of the second box is “Please enter a number:”, followed by which you can input anything.

You can think of the input function as having an embedded print().

It’s important to note that the results of input are default str (string) type. If you need to perform calculations on the data, it is recommended to use [forced conversion](Python Basic Data Types and Data Type Conversion (g2022cyk.top)).

image-20221116191309647

Although it looks like assigning a value to the input() function, in reality, we are assigning the result of the input() function’s execution (the collected information) to the variable a.

In simple terms, what we put into the a box is not the question asked in the input() function but the answers collected through the input() function.

Thus, no matter what you input in the terminal, no matter how many times you change your answer, as long as it is a response to the question asked by the input() function, it will be stored in the variable. When you print the variable, the answer will be extracted and displayed on the screen.

These pieces of information/answers/data displayed in the terminal in the code world can be referred to as input values—the content we input to the function.