python基礎篇—編程入門程序

1、小程序
實現用戶交互,引號,判斷用法,變量實現。
[root@node1 day1]# cat jiaohu.py
#!/usr/bin/env python
#!coding:utf-8
name = raw_input('what your name?: ')
age = raw_input('how old are you?: ')
sex = raw_input('what your sex?: ')
job = raw_input('what is yout jobs?: ')
msg = """
Infomation of commpany staff:
Name : \033[42;1m%s\033[0m;
Age : %s
Sex : \033[31;1m%s \033[0m;
Job : %s
""" %(name, age, sex, job)
if int(age)>50:
print "You too old, you can onlu work ..."
elif int(age)>30:
print "you are in middle age, go on ..."
else:
print 'you still very young ...'
print msg
[root@node1 day1]#

2、while循環練習
[root@node1 day1]# cat whilet.py
#!/usr/bin/env python
#!coding:utf-8
i = 0
while True:
i = i + 1
if i == 5:
print 'I have got to the 50th'
continue
elif i>9:break
print i

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章