Size: 3454
Comment:
|
Size: 740
Comment: 删除对PageComment2组件的引用
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
## page was renamed from ObpLovelyPython/LpyAttach-answer ## page was renamed from ObpLovelyPython/Answer |
|
Line 2: | Line 4: |
#pragma section-numbers on | #pragma section-numbers off |
Line 4: | Line 6: |
||'''status'''|| 校对 || ShengYan || 完成度70%|| | ||'''status''' || 校对 || lizzie || 完成度100% || [[TableOfContents(2)]] |
Line 6: | Line 9: |
## 编辑正文收集在: ### http://openbookproject.googlecode.com/svn/trunk/LovelyPython/exercise/part2-KDays/LpyAttach3answer-KDays.moin ### http://openbookproject.googlecode.com/svn/trunk/LovelyPython/exercise/part1-CDays/LpyAttach3answer-CDays.moin |
|
Line 7: | Line 13: |
[[TableOfContents]] | ##startInc = 故事练习解答 = |
Line 9: | Line 16: |
= 故事练习解答 = == CDays == === CDays-5 === |
== CDays 故事解答 == [[Include(/CDays,,from="^##startInc",to="^##endInc")]] |
Line 13: | Line 19: |
* 计算今年是闰年嘛? 相关代码: {{{#!python #coding:utf-8 '''cdays-5-exercise-1.py this year is a leap year or not @author: U{shengyan<mailto:[email protected]>} @version:$Id$ ''' import time #导入time模块 |
== KDays 故事解答 == [[Include(/KDays,,from="^##startInc",to="^##endInc")]] |
Line 23: | Line 22: |
thisyear = time.localtime()[0] #获取当前年份 if thisyear % 400 == 0 or thisyear % 4 ==0 and thisyear % 100 <> 0: #判断闰年条件,满足模400为0,或者模4为0但模100不为0 print 'this year %s is a leap year' % thisyear else: print 'this year %s is not a leap year' % thisyear }}} * 利用python作为科学计算器。熟悉Python中的常用运算符,并分别求出表达式12*34+78-132/6、(12*(34+78)-132)/6、(8.6/4)**5的值。并利用`math`模块进行数学计算,分别求出145/23的余数,0.5的sin和cos值等等,详细可参考help(math)。 相关代码: {{{#!python #coding:utf-8 '''cdays-5-exercise-2.py basic operation and math library @author: U{shengyan<mailto:[email protected]>} @version:$Id$ ''' x = 12*34+78-132/6 #表达式计算 y = (12*(34+78)-132)/6 z = (8.6/4)**5 print '12*34+78-132/6 = %d' % x print '(12*(34+78)-132)/6 = %d' % y print '(8.6/4)**5 = %f' % z import math #导入数学计算模块 a = math.fmod(145, 23) #求余函数 b = math.sin(0.5) #正弦函数 c = math.cos(0.5) #余弦函数 print '145/23的余数 = %d' % a print 'sin(0.5) = %f' %b print 'cos(0.5) = %f' %c }}} * 编写程序,在屏幕上打印出如下图案: attachment:cdays-5-exercise-3.png 相关代码: {{{#!python #coding:utf-8 '''cdays-5-exercise-3.py print out and for expression @author: U{shengyan<mailto:[email protected]>} @version:$Id$ ''' for index in range(1, 6): if index > 3: index = 2*3 -index #调整index print ' '*(3-index), #输出每行空格个数 print '*'*(2*index - 1) #输出每行*的个数 }}} 截图 === CDays-4 === * os 模块中还有哪些功能可以使用? -- 提示使用 `dir()` `help()` * `open()` 还有哪些模式可以使用? * 尝试`for .. in ..` 循环可以对哪些数据类型进行操作? * 格式化声明,还有哪些格式可以进行约定? * 现在的写入文件模式好嘛? 有改进的余地? '''CDay-4-5.py''' 好在哪里? : {{{#!python # coding : utf-8 import os export = "" for root, dirs, files in os.walk('/media/cdrom0'): export+="\n %s;%s;%s" % (root,dirs,files) open('mycd2.cdc', 'w').write(export) }}} '''CDay-4-6.py''' 又更加好在哪里? : {{{#!python # coding : utf-8 import os export = [] for root, dirs, files in os.walk('/media/cdrom0'): export.append("\n %s;%s;%s" % (root,dirs,files)) open('mycd2.cdc', 'w').write(''.join(export)) }}} * 读取文件cdays-4-test.txt内容,去除空行和注释行后,以行为单位进行排序,并将结果输出为cdays-4-result.txt。 === CDays-3 === === CDays-2 === === CDays-1 === === CDays-0 === === CDays+1 === === CDays+2 === === CDays+3 === == KDays == == 小结 == ## 总体语法等等叙述,注意给出相关知识的阅读指导 |
##endInc |
Line 126: | Line 24: |
::-- ZoomQuiet [[[DateTime(2008-04-26T07:41:41Z)]]] [[PageComment2]] |
status |
校对 |
lizzie |
完成度100% |
故事练习解答
CDays 故事解答
Include(/CDays,,from="^##startInc",to="^##endInc")
KDays 故事解答
Include(/KDays,,from="^##startInc",to="^##endInc")