num= 1 #值 =1while num <= 10 : # num(1)小於10 print(num) # 應該列印 這個1的值 num +=1 # num+=1等價於 num再加1 所以這個值一共是2 if num == 6: #如果為6 這個程式終止,如果沒有到6,那麼程式將會一遍一遍的走直 ...
num= 1 #值 =1
while num <= 10 : # num(1)小於10
print(num) # 應該列印 這個1的值
num +=1 # num+=1等價於 num再加1 所以這個值一共是2
if num == 6: #如果為6 這個程式終止,如果沒有到6,那麼程式將會一遍一遍的走直到走到6
break
例如:
while num <= 10 : 這句話num的值是1,那麼print則會判定列印 1
但是在執行到了mum+ =1的地方,num這個值就被往上加了一位 變成了2
但是依舊沒有達到終止程式的條件,所以還要走第二輪。
已知第一輪最後num的值為2,那麼在此到達num+=1的地方 則會變成3,但是依舊沒有達到終止條件,
這樣就會繼續吧 4、 5都按照以上方法輸出一遍,到6自動停止。
所以最後得出的結果應該是 12345
while 變數判定
age = 18 #設變數為18
sign = True # sige變數等於(真)可判定條件
while sign : #while sign:定義
guess =int(input("guess_age:")) # guess = 用戶交互器所填寫的數據
if guess == age: #如果 guess變數等於 age變數 那麼
print("Yes Good!") #則判定 列印 yes
sign = False #如果 sign 等於 (假)不可執行條件
elif guess < age : #如若 guess 小於 age的值 那麼
print("you need to enter one bingger!")#則判定列印 you need to neter one bigger
else: #否則
print("you need to enter one smaller!") #則列印you need to enter one smaller!
print("end!") # 結束!
break 終止判定
age = 18
while True :#當判定(真)正確時
guess =int(input("guess_age:"))
if guess == age:#如果guess值等於 age那麼
print("Yes Good!")#判定為 yes good!
break #並終止!
elif guess < age : #否則如果 guess小於age
print("you need to enter one bingger!")
else:
print("you need to enter one smaller!")
print("end!")
while迴圈計算規則: