码迷,mamicode.com
首页 > 编程语言 > 详细

python代码学习day01

时间:2016-01-15 12:34:34      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

这段时间在学习一些python的基础 贴上今天学的内容 以供以后回来看看,自己当时有多傻

 1 #!/usr/bin/env python 
 2 #coding:utf8  
 3 
 4 print_num = 0
 5 count = 0
 6 while count < 100:
 7     if count == print_num:
 8         print "There you got the number:",count 
 9         choice = raw_input("Do you want to continue to the loop?(y|n)")
10         if choice == n:
11             break
12         else:
13             while print_num <= count:
14                 print_num = input("Which loop do you want it to be printed out?")
15                 if print_num <= count:
16                     print u"已经过了!baby!"
17     else:
18         print Loop:,count 
19     count +=1
20 else:
21     print "Loopmax:",count

以上代码的功能

1 首先判断 count 和print_num是否相等

2 如果相等 则咨询你是否要继续这个循环 如果不 退出

3 否则 当print_num是小于等于count的时候 咨询你 你想打印到哪个循环 比如30  判断这个30是否小于count 如果是 提示已经过了

4 如果没有 就一直打印loop:...知道30为止 到了会问你 还要继续打印其他么,如果你输入了大于30的数 会一直打印下去 知道 大于count 这时候最后输出loopmax是多少

结果导视

There you got the number: 0
Do you want to continue to the loop?(y|n)y
Which loop do you want it to be printed out?10
Loop: 1
Loop: 2
Loop: 3
Loop: 4
Loop: 5
Loop: 6
Loop: 7
Loop: 8
Loop: 9
There you got the number: 10
Do you want to continue to the loop?(y|n)y
Which loop do you want it to be printed out?2
已经过了!baby!
Which loop do you want it to be printed out?

 如果输出大于100的

Which loop do you want it to be printed out?101
Loop: 11
...
Loop: 95
Loop: 96
Loop: 97
Loop: 98
Loop: 99
Loopmax: 100

  

python代码学习day01

标签:

原文地址:http://www.cnblogs.com/olinux/p/5132829.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!