#!/user/bin/env python print 'Hello world!'
#!/usr/bin/env python name = raw_input("Please input your name:") if name == 'Madon': #判断名字等于Madon 等于看以下内容,不等于看else print 'Good afternoon,', name print "hahaha" else: print 'Soory , I do not know you!', name
#!/usr/bin/env python this_year = 2015 name = raw_input("please input your name:") age = int(raw_input("how old are your?")) sex = raw_input("please input your sex:") dep = raw_input("which department:") message = '''Information of the company staff: Name: %s Age : %d #这里用了d,类型转换了一下,以下是对类型进行判断 Sex : %s Dep :%s ''' % (name,age,sex,dep) print message if age < 28: print "Cangratulations! you've got!" elif age == 28: print "xiuxi 2xiaosih" else: print "get back work"
#!/usr/bin/env python name = raw_input('what is your name?:') age = raw_input('how old are you?:') job = raw_input('what is your job?:') msg = """ Information of %s as below: Name : \033[42;1m%s \033[0m #这里42 为背景色 #如果是字体颜色为 Name : \033[32;1m%s \033[0m Age : %s Job : %s """ %(name,name,age,job) if int(age) >= 50: print "you are too old,you can only work" elif int (age) >=30: print "you are too old, you can only work for ..." elif int (age) <20: print "you wei cheng nian" else: print "old your xia" print msg
#!/usr/bin/env python name = raw_input('what is your name?:').strip() if len(name) == 0: print 'ERROR: you must input sth as name.' #判断用户输入name 的时候 #前面空格自动忽略,后面空格只保留一个格。空间空格不变 #报错继续向下执行 age = raw_input('how old are you?:') job = raw_input('what is your job?:') msg = """ Information of %s as below: Name : \033[42;1m%s \033[0m Age : %s Job : %s """ %(name,name,age,job) if int(age) >= 50: print "you are too old,you can only work" elif int (age) >=30: print "you are too old, you can only work for ..." elif int (age) <20: print "you wei cheng nian" else: print "old your xia" print msg
>>> for i in range(1,5): ... print i ... 1 2 3 4 >>>
>>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>>
>>> range(1,100,2) [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99] >>>
>>> for i in range(10): ... if i == 5: ... print 'i have got to the round 5th!' ... print i ... 0 1 2 3 4 i have got to the round 5th! 5 6 7 8 9 >>>
[root@mysql-5 day1]# python for.py 0 1 2 3 4 I hava got to the round 5th! [root@mysql-5 day1]# cat for.py #!/usr/bin/env python for i in range(10): if i == 5: print "I hava got to the round 5th!" break print i
continue 到上一及循环里;break 退出整个循环
[root@mysql-5 day1]# python for.py 0 1 2 3 4 6 7 8 9 [root@mysql-5 day1]# cat for.py #!/usr/bin/env python for i in range(10): if i == 5: # print "I hava got to the round 5th!" continue print i
#!/usr/bin/nev python i = 0 while True: i = i + 1 if i == 50: print 'I hava got to the round 50th!' continue elif i> 70:break print i
python 的导入模块 跟算法 这里略过了