與小卡特一起學python 第8章 轉圈圈 FOR迴圈和條件迴圈
#8章 轉圈圈
#8.1 一個非常簡單的FOR迴圈
for looper in [1,2,3,4,5]:
print ("hello")
#8.2 每次for 迴圈做不同的事情
for looper in [1,2,3,4,5]:
print (looper)
#8.3 計數迴圈 列印8的乘法表
for looper in [1,2,3,4,5]:
print (looper,"times 8 =",looper * 8)
#print (looper,"times 3 =",looper * 3,"times 4 =",looper * 4,"times 5 =",looper * 5)
#8.4 一條捷徑 range()
for looper in range(1,5):
print (looper,"times 8 =",looper * 8)
#8.5 使用range()列印8的乘法表
for looper in range(1,11):
print (looper,"times 8 =",looper * 8)
# 迴圈變數名 慣例 i,j,k
for i in range(1,5):
print (i,"hello")
# range()簡寫 range(5) 等用range(0,5)
for i in range(5):
print (i,"hello")
# 也可以用字串列表來迴圈
for letter in ("Hi there"):
print(letter)
#傳遞形參
for i in range(1,10,2):
print (i)
for i in range(2,10,2):
print (i)
for i in range(5,26,5):
print(i)
for i in range (10,0,-1):
print(i)
#8.6 準備好了嗎?
import time
for i in range (10,0,-1):
print(i)
time.sleep(1)
print("Blast off!")
#8.7 誰最酷?
for cool_guy in ["Spongebob","Spiderman","Justin Timberlake","My Dad"]:
print (cool_guy,"is the coolest guy ever!")
#8.8 條件或者while迴圈
print("Type 3 to contiue,anything else to quit.")
someInput = input()
while someInput == '3':
print("Thank you for the 3.Very kind of you.")
print("Type 3 to contiue,anything else to quit.")
someInput = input()
print("That's not 3,so I'm quitting now.")
#8.9 迴圈中使用continue
for i in range (1,6):
print()
print("i=",i,)
print("hello,how ",end='') #python3 中end=''不換行。python3和python2的一些區別
if i == 3:
continue
print("are you today?")
#8-9 break跳出迴圈,不再計數
for i in range (1,6):
print()
print("i=",i,)
print("hello,how ",end='') #python3 中end=''不換行。python3和python2的一些區別
if i == 3:
break
print("are you today?")
#8.1 一個非常簡單的FOR迴圈
for looper in [1,2,3,4,5]:
print ("hello")
#8.2 每次for 迴圈做不同的事情
for looper in [1,2,3,4,5]:
print (looper)
#8.3 計數迴圈 列印8的乘法表
for looper in [1,2,3,4,5]:
print (looper,"times 8 =",looper * 8)
#print (looper,"times 3 =",looper * 3,"times 4 =",looper * 4,"times 5 =",looper * 5)
#8.4 一條捷徑 range()
for looper in range(1,5):
print (looper,"times 8 =",looper * 8)
#8.5 使用range()列印8的乘法表
for looper in range(1,11):
print (looper,"times 8 =",looper * 8)
# 迴圈變數名 慣例 i,j,k
for i in range(1,5):
print (i,"hello")
# range()簡寫 range(5) 等用range(0,5)
for i in range(5):
print (i,"hello")
# 也可以用字串列表來迴圈
for letter in ("Hi there"):
print(letter)
#傳遞形參
for i in range(1,10,2):
print (i)
for i in range(2,10,2):
print (i)
for i in range(5,26,5):
print(i)
for i in range (10,0,-1):
print(i)
#8.6 準備好了嗎?
import time
for i in range (10,0,-1):
print(i)
time.sleep(1)
print("Blast off!")
#8.7 誰最酷?
for cool_guy in ["Spongebob","Spiderman","Justin Timberlake","My Dad"]:
print (cool_guy,"is the coolest guy ever!")
#8.8 條件或者while迴圈
print("Type 3 to contiue,anything else to quit.")
someInput = input()
while someInput == '3':
print("Thank you for the 3.Very kind of you.")
print("Type 3 to contiue,anything else to quit.")
someInput = input()
print("That's not 3,so I'm quitting now.")
#8.9 迴圈中使用continue
for i in range (1,6):
print()
print("i=",i,)
print("hello,how ",end='') #python3 中end=''不換行。python3和python2的一些區別
if i == 3:
continue
print("are you today?")
#8-9 break跳出迴圈,不再計數
for i in range (1,6):
print()
print("i=",i,)
print("hello,how ",end='') #python3 中end=''不換行。python3和python2的一些區別
if i == 3:
break
print("are you today?")
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/220205/viewspace-2073984/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 與小卡特一起學python 第11章 巢狀與可變迴圈Python巢狀
- Python條件語句與迴圈Python
- python條件判斷與迴圈Python
- JS迴圈和條件分支JS
- Python 分支、迴圈、條件與列舉Python
- 條件分支與迴圈結構學習
- 【小知識】QueryWrapper迴圈or條件APP
- 草根學Python(五) 條件語句和迴圈語句Python
- 與小卡特一起學python 第11章 巢狀與可變迴圈 動手試一試Python巢狀
- SqlServer中迴圈和條件語句SQLServer
- Python-條件語句和迴圈語句Python
- PHP 條件迴圈鞏固PHP
- Python基礎:條件判斷 & 迴圈Python
- AWK if(條件)語句與迴圈簡介
- Vue學習筆記(三)條件渲染和迴圈渲染Vue筆記
- vue.js第四課 條件與迴圈Vue.js
- Python學習筆記3(條件語句+迴圈語句)Python筆記
- Python學習筆記(三)——條件語句、迴圈語句Python筆記
- Scala與Java差異(二)之條件控制與迴圈Java
- JavaScript的map迴圈、forEach迴圈、filter迴圈、reduce迴圈、reduceRight迴圈JavaScriptFilter
- Go的100天之旅-07條件和迴圈Go
- 探討兩種迴圈表示方法的區別,while迴圈與for迴圈的小總結While
- 豬行天下之Python基礎——4.1 條件判斷與迴圈Python
- python 基礎習題6--for迴圈和while迴圈PythonWhile
- WordPress開發入門06:條件判斷與迴圈
- python 迴圈Python
- Python迴圈Python
- 人人都能學會的python程式設計教程8:條件判斷與迴圈Python程式設計
- C語言——迴圈結構(for迴圈,while迴圈,do-while迴圈)C語言While
- Java入門學習-學習if & else,for迴圈,foreach迴圈,while迴圈的用法。JavaWhile
- 條件迴圈語句組成了Python程式碼的骨架Python
- 無限for迴圈(死迴圈)
- javascript新手入門之條件語句,迴圈JavaScript
- for迴圈、break和continue、二重迴圈
- Iterator 和 for…of 迴圈
- 《快學 Go 語言》第 3 課 —— 分支與迴圈Go
- python while迴圈PythonWhile
- Python迴圈控制-forPython