3、('Enterfivenumber')v=[]i=0s=0whilei<5:a=input('n%d='%(i+1))v.extend([int(a)])s=s+v[i]i+=1print(v)print('sum=%d'%s)for循環(huán)print('Enterfivenumber')v=[]s=0foriinrange(5):a=input('n%d='%(i+1))v.extend([int(a)])s=s+v[i]print(v)print('sum=%d'%s)2--9print('Enterfivenumber
4、')v=[]s=0foriinrange(5):a=input('n%d='%(i+1))v.extend([int(a)])s=s+v[i]print(v)print('ave=%f'%(float(s)/len(v)))2-10i=1whilei:n=int(input('Enteranumberbetween1-100:'))ifn<=100andn>=1:print('Done')i=0else:print('Error')2-11whileTrue:s=0c=int(input("'1'sum,'2'ave,'
5、0'exit:"))ifc==1:foriinrange(5):n=int(input('n%d='%(i+1)))s+=nprint(s)ifc==2:foriinrange(5):n=int(input('n%d='%(i+1)))s+=nprint(float(s/5))ifc==0:break2-15a=int(input('a='))b=int(input('b='))c=int(input('c='))n=[]ifa>b:a,b=b,aifa>c:a,c=c,aifb>c:b,c=c,bn.extend(
6、[a,b,c])print(n)python核心練習(xí)(第三章)importosls=os.linesepdefwrite():whileTrue:fname=input('Enterfilename:')ifos.path.exists(fname):print('Error%salreadyexists'%fname)else:breakall=[]print("Enterlines('.'byitselftoquit).")whileTrue:entry=input('>')ifentry=='.':brea
7、kelse:all.append(entry)fobj=open(fname,'w')fobj.writelines(['%s%s'%(x,ls)forxinall])fobj.close()print('Done')defread():whileTrue:fname=input('Enterfilename:')ifnotos.path.exists(fname):print('sorry,%sisnotexists'%fname)else:breaktry:fobj=open(fname,'r')exceptIOEr
8、rorase:print("***fileopenerror",e)else:foreachlineinfobj:print(eachline),fobj.close()i=0whilei!='q':i=input("'r'read,'w',write,'q'quite:")ifi=='r':read()elifi=