I will explain using relatively simple language, and I will provide analogies for each code snippet. It may become aesthetically tiring, so I hope for your support.
print()
The meaning is “print”, which is to output. You can fill the parentheses with numbers, strings (which must be enclosed in quotes), and variables.For example: when you run this code, the computer will “speak” the content you filled in the parentheses on the screen.
input()
When you run this code, it will display the content inside the parentheses and prompt you to input something.For example: a person asks you a question, and the content of that question is what is inside the parentheses, then you answer the question (input), and he will record your answer.You can write numbers, strings, or variables as prompts inside the parentheses.
for i in range():
This is a loop, where “i” can be replaced with other letters as a variable. You can fill the parentheses with numbers and variables to indicate the number of iterations.Each time the loop runs, “i” will increment by 1, starting from 0 in the first iteration.For example: a person does the same thing multiple times, and each time they do it in the loop, they start counting from 0 and add 1 each time.
if:...else:
This is the if…else statement (familiar to those who have learned about search).After if, you can add conditions, such as <= for less than or equal to, >= for greater than or equal to, == for equal to (note that it uses two equal signs), and != for not equal. For example:
if a==1:...
There is also a possibility that if you want to check if a is less than 3 and greater than 0, you can connect them with and. If you want to check if a equals 0 or 5, you can connect them with or.and represents conjunction, while or represents disjunction.The meaning of else is also quite straightforward: if the previous condition is not satisfied, then run the code under else.I’ll write four for now; if you like it, I will continue writing.