1, output formatting and placeholders
Sample Code
1 # formatted output 2 # % SD . 3 # name = INPUT ( 'Enter your name') . 4 # Age = INPUT ( 'Enter Age') . 5 # height = INPUT ( 'Enter height') . 6 # MSG = " my name is% s, year% s height% s "% (name, Age, height) 7 # Print (msg) 8 " "" 9 name = the iNPUT ( 'Please enter your name:') 10 Age = the iNPUT ( 'Please enter Age: ') 11 the job the iNPUT = (' Please enter the work: ') 12 Hobbie = the iNPUT (' your hobby: ') 13 14 msg =' '' ------------ info of% ----------- S 15 the Name: %s 16 Age : %d 17 Job:% S 18 is Hobbie:% S . 19 ------------- End ----------------- '' '% (name, name, int (Age), Job, Hobbie) 20 is Print (MSG) 21 is "" " 22 is name = iNPUT ( ' enter your name ' ) 23 is Age = iNPUT ( ' enter Age ' ) 24 height = iNPUT ( ' enter height ' ) 25 msg = " my name is% s,% s this height is% s learning progress %% S 3 " % (name, Age, height) 26 Print (msg)
2, while else statements
. 1 COUNT = 0 2 the while COUNT <=. 5 : . 3 COUNT + =. 1 . 4 IF COUNT ==. 3: BREAK . 5 Print ( " Loop " , COUNT) . 6 . 7 the else : . 8 Print ( " loop done for normal execution " ) . 9 Print ( " ----- ------ OUT of the while Loop " )
3, the logic
1 #and or not 2 #优先级,()> not > and > or 3 # print(2 > 1 and 1 < 4) 4 # print(2 > 1 and 1 < 4 or 2 < 3 and 9 > 6 or 2 < 4 and 3 < 2) 5 # T or T or F 6 #T or F 7 # print(3>4 or 4<3 and 1==1) # F 8 # print(1 < 2 and 3 < 4 or 1>2) # T 9 # print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) # T 10 # print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) # F 11 # print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F 12 # Print (Not 2>. 3. 1 and <. 4. 4 or>. 5 and 2>. 9. 1 and> or. 8. 7 <. 6) F. # 13 is 14 # PS int ----> BOOL converted to the nonzero converted bool True 0 bool is False 15 # Print (bool (2)) 16 # Print (bool (-2)) . 17 # Print (bool (0)) 18 is # #bool ---> int . 19 # Print (int (True)) # . 1 20 is # Print (int (False)) # 0 21 is 22 is 23 is '' ' X or YX True, it returns X ' '' 24 # Print (. 1 or 2) #. 1 25 # Print (. 3 or 2) #. 3 26 is # Print (or 0 2) # 2 27 # print(0 or 100) # 100 28 29 30 # print(2 or 100 or 3 or 4) # 2 31 32 # print(0 or 4 and 3 or 2) 33 '''x and y x True,则返回y''' 34 # print(1 and 2) 35 # print(0 and 2) 36 print(2 or 1 < 3) 37 print(3 > 1 or 2 and 2)