Python核心第二版习题答案-.pdf
《Python核心第二版习题答案-.pdf》由会员分享,可在线阅读,更多相关《Python核心第二版习题答案-.pdf(12页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Pytho 核心编程第二版(第二,三,四,五章)答案第二章2-3 a=int(input(A=)b=int(input(B=)print(A-B=%d,A+B=%dnA/B=%d,A*B=%d,A%B=%d%(a-b,a+b,a/b,a*b,a%b)2-4(a)print(input(Enter a string:)(b)print(int(input(Enter a value:)2-5(a)i=0 whilei11:print(i)i+=1(b)fori in range(11):print(i)2-6 v=int(input(Enter a number to determine pos
2、itive or negative:)if v0:print(%d is negative%v)elif v=0:print(you enter zero)else:print(%d is positive%v)2-7 while 循环s=input(Enter a string:)i=0 whileilen(s):print(si)i+=1 for 循环s=input(Enter a string:)fori in s:print(i)2-8 while 循环print(Enter five number)v=i=0 s=0 whilei5:a=input(n%d=%(i+1)v.exten
3、d(int(a)s=s+vi i+=1 print(v)print(sum=%d%s)for 循环print(Enter five number)v=s=0 fori in range(5):a=input(n%d=%(i+1)v.extend(int(a)s=s+vi print(v)print(sum=%d%s)2-9 print(Enter five number)v=s=0 fori in range(5):a=input(n%d=%(i+1)v.extend(int(a)s=s+vi print(v)print(ave=%f%(float(s)/len(v)2-10 i=1 whil
4、e i:n=int(input(Enter a number between 1-100:)if n=1:print(Done)i=0 else:print(Error)2-11 while True:s=0 c=int(input(1sum,2ave,0exit:n)if c=1:fori in range(5):n=int(input(n%d=%(i+1)s+=n print(s)if c=2:fori in range(5):n=int(input(n%d=%(i+1)s+=n print(float(s/5)if c=0:break 2-15 a=int(input(a=)b=int(
5、input(b=)c=int(input(c=)n=if ab:a,b=b,a if ac:a,c=c,a if bc:b,c=c,b n.extend(a,b,c)print(n)第三章;importos ls=os.linesep def write():while True:fname=input(Enter file name:)ifos.path.exists(fname):print(Error%s already exists%fname)else:break all=print(nEnter lines(.by itself to quit).n)while True:entr
6、y=input()if entry=.:break else:all.append(entry)fobj=open(fname,w)fobj.writelines(%s%s%(x,ls)for x in all)fobj.close()print(Done)def read():while True:fname=input(Enter filename:)if not os.path.exists(fname):print(sorry,%s is not exists%fname)else:break try:fobj=open(fname,r)exceptIOError as e:print
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Python 核心 第二 习题 答案
限制150内