一、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