status

校对

ShengYan

完成度70%

TableOfContents

1. 故事练习解答

1.1. CDays

1.1.1. CDays-5

   1 #coding:utf-8
   2 '''cdays-5-exercise-1.py this year is a leap year or not
   3     @author: U{shengyan<mailto:[email protected]>}
   4     @version:$Id$
   5 '''
   6 #导入time模块
   7 import time
   8 #获取当前年份
   9 thisyear = time.localtime()[0]
  10 #判断闰年条件,满足模400为0,或者模4为0但模100不为0
  11 if thisyear % 400 == 0 or thisyear % 4 ==0 and thisyear % 100 <> 0:
  12         print 'this year %s is a leap year' % thisyear
  13 else:
  14         print 'this year %s is not a leap year' % thisyear

   1 #coding:utf-8
   2 '''cdays-5-exercise-2.py basic operation and math library
   3     @author: U{shengyan<mailto:[email protected]>}
   4     @version:$Id$
   5 '''
   6 #表达式计算
   7 x = 12*34+78-132/6
   8 y = (12*(34+78)-132)/6
   9 z = (8.6/4)**5
  10 
  11 print '12*34+78-132/6 = %d' % x
  12 print '(12*(34+78)-132)/6 = %d' % y
  13 print '(8.6/4)**5 = %f' % z
  14 
  15 #导入数学计算模块
  16 import math
  17 #求余函数
  18 a = math.fmod(145, 23)
  19 #正弦函数
  20 b = math.sin(0.5)
  21 #余弦函数
  22 c = math.cos(0.5)
  23 
  24 print '145/23的余数 = %d' % a
  25 print 'sin(0.5) = %f' %b
  26 print 'cos(0.5) = %f' %c

attachment:cdays-5-exercise-3.png

   1 #coding:utf-8
   2 '''cdays-5-exercise-3.py print out and for expression
   3     @author: U{shengyan<mailto:[email protected]>}
   4     @version:$Id$
   5 '''
   6 
   7 for index in range(1, 6):
   8         if index > 3:
   9                 #调整index
  10                 index = 2*3 -index
  11         #输出每行空格个数       
  12         print ' '*(3-index),
  13         #输出每行*的个数
  14         print '*'*(2*index - 1)

截图

1.1.2. CDays-4

CDay-4-5.py 好在哪里? :

   1 # coding : utf-8
   2 import os
   3 export = ""
   4 for root, dirs, files in os.walk('/media/cdrom0'):
   5   export+="\n %s;%s;%s" % (root,dirs,files)
   6 open('mycd2.cdc', 'w').write(export)

CDay-4-6.py 又更加好在哪里? :

   1 # coding : utf-8
   2 import os
   3 export = []
   4 for root, dirs, files in os.walk('/media/cdrom0'):
   5     export.append("\n %s;%s;%s" % (root,dirs,files))
   6 open('mycd2.cdc', 'w').write(''.join(export))

1.1.3. CDays-3

1.1.4. CDays-2

1.1.5. CDays-1

1.1.6. CDays-0

1.1.7. CDays+1

1.1.8. CDays+2

1.1.9. CDays+3

1.2. KDays

1.3. 小结


::-- ZoomQuiet [DateTime(2008-04-26T07:41:41Z)] PageComment2