#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/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/220205/viewspace-2073984/