Chinaunix首页 | 论坛 | 博客
  • 博客访问: 202910
  • 博文数量: 64
  • 博客积分: 2536
  • 博客等级: 少校
  • 技术积分: 610
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-16 16:39
文章分类

全部博文(64)

文章存档

2011年(2)

2010年(1)

2009年(61)

我的朋友

分类:

2009-09-21 14:08:58

 

#!/usr/bin/python
# Filename: if.py


number = 23
guess = int(raw_input('Enter an integer : '))

if guess == number:
    print 'Congratulations, you guessed it.' # New block starts here
    print "(but you do not win any prizes!)" # New block ends here
elif guess < number:
    print 'No, it is a little higher than that' # Another block
    # You can do whatever you want in a block ...
else:
    print 'No, it is a little lower than that'
    # you must have guess > number to reach here

print 'Done'
# This last statement is always executed, after the if statement is

#!/usr/bin/python
# Filename: while.py


number = 23
running = True

while running:
    guess = int(raw_input('Enter an integer : '))

    if guess == number:
        print 'Congratulations, you guessed it.'
        running = False # this causes the while loop to stop
    elif guess < number:
        print 'No, it is a little higher than that'
    else:
        print 'No, it is a little lower than that'
else:
    print 'The while loop is over.'
    # Do anything else you want to do here

print 'Done'

#!/usr/bin/python
# Filename: for.py


for i in range(1, 5):
    print i
else:
    print 'The for loop is over'

#!/usr/bin/python
# Filename: break.py


while True:
    s = raw_input('Enter something : ')
    if s == 'quit':
        break
    print 'Length of the string is', len(s)
print 'Done'

#!/usr/bin/python
# Filename: continue.py


while True:
    s = raw_input('Enter something : ')
    if s == 'quit':
        break
    if len(s) < 3:
        continue
    print 'Input is of sufficient length'
    # Do other kinds of processing here...

阅读(893) | 评论(0) | 转发(0) |
0

上一篇:可以用sudo命令

下一篇:第7章 函数

给主人留下些什么吧!~~