python之if和while控制流
IF语句的判断输出
1 #!/usr/bin/env python 2 #coding:utf-8 3 4 name = raw_input("请输入你的名字:") 5 age = input("请输入你的年龄:") 6 job = raw_input("请输入你的工作:") 7 salary = input("请输入你的工资:") 8 9 print ''' 10 name: %s 11 age : %d 12 job : %s 13 salary : %d 14 ================================== 15 +++++++++++++++++++++++++++++++++++ 16 '''%(name,age,job,salary) 17 if age > 30: 18 print "你很年轻" 19 elif age<40: 20 print "你是青年" 21 else: 22 print "你很年轻"
for语句循环输出
1 #!/usr/bin/env python 2 #coding:utf-8 3 4 name = raw_input("请输入你的名字:") 5 job = raw_input("请输入你的工作:") 6 salary = input("请输入你的工资:") 7 8 real_age=30 9 for i in range(10): 10 age = input("请输入你的年龄:") 11 if age < 30: 12 print "请猜大一点" 13 elif age==30: 14 print "GOOD " 15 break 16 else: 17 print "请猜小一点" 18 #print "你还有 %s 机会"% (9 - i) 19 20 21 print ''' 22 name: %s 23 job : %s 24 age :%s 25 salary : %d 26 ================================== 27 +++++++++++++++++++++++++++++++++++ 28 '''%(name,job,age,salary)