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 import time                                                                                                             #导入time模块
   7 
   8 thisyear = time.localtime()[0]                                                                          #获取当前年份
   9 
  10 if thisyear % 400 == 0 or thisyear % 4 ==0 and thisyear % 100 <> 0:             #判断闰年条件,满足模400为0,或者模4为0但模100不为0
  11         print 'this year %s is a leap year' % thisyear
  12 else:
  13         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 import math                             #导入数学计算模块
  16 
  17 a = math.fmod(145, 23)          #求余函数
  18 b = math.sin(0.5)                       #正弦函数
  19 c = math.cos(0.5)                       #余弦函数
  20 
  21 print '145/23的余数 = %d' % a
  22 print 'sin(0.5) = %f' %b
  23 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 = 2*3 -index              #调整index
  10         print ' '*(3-index),                    #输出每行空格个数
  11         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