python下if/for/while用法

一、if 判断

#!/usr/bin/python
#coding=utf-8
name = raw_input('Name:')
age = int(raw_input('Age:'))
job = raw_input('Job:')

print "-------------------------\n"

if age < 28:
    print "Congratulations,you have the holiday at May 4th!"
elif name == 'zhangsan':
    print "You can do it as you had sent a gift to you boss!"
else:
    print "Don't even think about it,get back to work!"

print '''
Name:%s
Age:%s
Job:%s''' %(name,age,job)

二、for 循环

#!/usr/bin/python
#coding=utf-8
#注意:有else和无else的区别

for i in range(1,6):
    if i == 3:
        print "great,you got your lucky number:",i
    print 'the number is:',i
print "---------------------------"
for i in range(1,6):
    if i == 3:
        print "great,you got your lucky number:",i
    else:
        print 'the number is:',i

三、while

#/usr/bin/python
#coding=utf-8

import tab

#while True:
#   input = raw_input("please input your username:")
#   if input == 'luyun':
#       password = raw_input("please input your password:")
#       p = 'redhat'
#       if password == p:
#           print "welcome to %s's home" %input
#           break
#       else:
#           print "wrong password!!try again"
#   else:
#       print "sorry,user %s not found" %input

#当密码输错后,实现不重新输用户名功能

while True:
    input = raw_input("please input your username:")
    if input == 'luyun':
        password = raw_input("please input your password:")
        p = 'redhat'
        while password != p:
            password = raw_input("worng password,try again:")
        else:
            print "welcome to %s's home" %input
            break
    else:
        print "sorry,user %s not found" %input
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值