Python learning notes (1), python learning notes
In fact, you can find a happy way to learn every language. If you are interested or have fun, you will always want to learn. Knowing print (), input (), and if/else can make a simple game.
Print () # print function, print the information out input () # print the information, and require that you enter a paragraph, and put this paragraph. If 1 + 1 = 2: print ('I am real, if 1 + 1 is equal to 2, it will print me !!! ') Else: print (' I am a false employee. If 1 + 1 is not equal to 2, it will print me ~~~ ') # Condition judgment statement
Then we can start playing the game through the three BIF functions learned above:
Print ('----------- WordGame -----------') number = int (input ("guess the number given by the system:") if number = 8: print ("wow, guessed it !! ") Else: print (" wrong! The number given by the system is 8! ")
Print ('----------- WordGame -----------')
Input function. This function displays the string on the IDLE and allows the user to input information and save this information to the number.
Note: input is of the string type by default. Here, we use int () to directly convert the input information to the int type.
Number = int (input ("guess the number given by the system :"))
The condition judgment statement is expressed in Chinese. If the number is 8, "Wow, guess" is printed. If the number is 8, "guess wrong!" is printed !"
If number = 8: print ("wow, guess it !! ") Else: print (" wrong! The number given by the system is 8! ")
Program flowchart
If you do not know how to break down a function, it is easier to understand it. If you write a program to draw a picture, the idea will be clear, and what you do is not easy to make mistakes.
>>> If c = 1: SyntaxError: invalid syntax
Summary of this learning function
Print () |
Print function |
Input () |
Input Function |
Dir (_ builtins __) |
View BIF |
Help (print) |
Help |
If and else |
Judgment statement |