One, variable
Print ('hello') " " -*-encoding:utf-8-*-print (' China hello ') #用其它调用的时候前面加这一串 ""age1 = 12age2 = Age1age3 = Age2age2 = 13print (age1,age2,age3)
variables
Note: How to print strings in various situations.
Second, string
" " MSG1 = ' Today is the first day ' MSG2 = ' come to Shahe class ' Print (MSG1 + msg2) " " " " MSG1 = ' stick ' Print (MSG1 * 3) " " " " name = input (' Please enter your name: ') Age = input (' Please enter your Age: ') print (name, ' This year ', ages, ' years old ' ) " "
string
Third, if statement
" " name = input (' Please enter your name: ') if name = = ' Liu Junjie ': #经常忘记写后面的冒号! The middle equals sign should be two (compare) print (' Beauty ') elif name = = ' Cheerleaders ': print (' handsome ') Else: #else后面也有冒号! print (' fool ') " " " " input (' Please enter a number ') if mum = = ' 0 ': mum2 = input (' Please enter second number ') #中间只有一个等号! if mum2 = = ' 9 ': print (' awesome ') #前面是两个tab, not an else: print (' No guess Right ')" 're = int (input (' Please enter a number ')) #数字转换int () If score >=100: print (' a ') elif score >=80: Print (' B ') elif score >=90: print (' C ') Else: #else应该顶格. print (' re-enter ') " "
if
Note: The equals sign after the If is two, indicating a comparison. And after the condition to add:, if there is else,else back also add:. Print when the front to the previous line dislocation of a tab;if else is a side-by-side relationship, all to shelf write.
Iv. circulation
" count = 1flag = Truewhile flag: #当变量flag值为真的时候满足条件while后面条件应该写flag变量而不是True, otherwise infinite loops. Print (count) Count = Count + 1 if count = = 101:flag = False
""
count = 0flag = Truewhile Flag:count = count + 2 p Rint (count) if count = = 100:flag = False count=1sum = 0while true:sum = sum + count count = Count + 1 if count = = 101:breakprint (sum) Span style= "COLOR: #800000" >count = 0while count <101:if count% 2 = = 0:print (count) Count = Count + 1 #前面是一个tab空格
Loops
1. Using the flag variable, while flag: jump out to if count = = 101:flag = Flase
2. Using Break, if count = = 101:break If the break is to move to the next line and then write, be sure to stagger a tab with the previous line
3. When the cycle is accumulated, be sure to remember print (sum), otherwise nothing will be output.
python18.4.26