与小卡特一起学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?")

    

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/220205/viewspace-2073984/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/220205/viewspace-2073984/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值