首页 > 编程语言 > 详细

python流程控制

时间:2015-10-29 11:10:12      阅读:159      评论:0      收藏:0      [点我收藏+]

4.流程控制和循环

age = raw_input(‘age:‘)
if  age>40:
    print  ‘old!‘
elif  age>30:
    print  ‘young!‘
else:
    print ‘younger!‘
if执行到情况匹配时就直接结束,并不是退出
else也可以省略
变量的声明等号  = 
赋值的定义是双等号   == 
 
for循环
for  *  in  * :
 

5.while循环

while循环默认是死循环
for循环有起始结束,循环次数
 
print_num = input(‘which loop do you want it to be printed out?‘)
count = 0
while count < 100000:
       if count == print_num:
            print ‘There you got  the number:‘,count
            choice = raw_input(‘Do you want to continue the loop?(y/n)‘)
            if choice == ‘n‘:
                 break
            else:
                  while print_num <= count:
                         print_num = inout(‘Which loop do you want it to be printed out?‘)
                         print u"pass"
       else:
              print ‘Loop:‘,count
       count  +=1      
 
else:
      print ‘loop:‘,count

python流程控制

原文:http://www.cnblogs.com/muzinan110/p/4919676.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!