您好,欢迎访问三七文档
当前位置:首页 > 机械/制造/汽车 > 《Python程序设计》题库
Python1.pythonx=int(input(Pleaseenterfirstinteger:))y=int(input(Pleaseentersecondinteger:))if(x==y):print()elif(xy):print(,x)else:print(,y);2pythona,b,c=3,4,5ifa=b:ifcb:print(b)else:print(c)else:ifca:print(a)else:print(c)3Python1100sum=0forxinrange(1,101):ifx%2==0:print(x)sum=sum+xprint(:,sum)4Python141002400year=int(input(Pleaseentertheyear:))if((year%4==0andyear%100!=0)or(year%400==0)):print(year,isaleapyear.)else:print(year,isnotaleapyear.)5Python3.25%cunkuan=10000#10000years=0whilecunkuan20000:years+=1cunkuan=cunkuan*(1+0.0325)print(str(years)+)60~100A~E90'A'80~89'B'70~79'C'60~69'D'60'E'score=int(input('0100'))ifscore100:grade=elifscore=90:grade='A'elifscore=80:grade='B'elifscore=70:elifgrade='C'elifscore=60:grade='D'elifscore=0:grade='E'else:grade=print(grade)70~9num=7whileTrue:guess=int(input('09'))ifguess==num:print()break;elifguessnum:print()else:print()81importmathn=int(input(:))x=int(math.sqrt(n))i,w=2,0foriinrange(2,x+1):ifn%i==0:w=1ifw==1:print(n,)else:print(n,)importmathn=int(input(''))i,w=2,0whilei=int(math.sqrt(n))andw==0:ifn%i==0:w=1breakelse:i=i+1ifw==0:print(n,)else:print(n,)importmathn=int(input(''))i=2whilei=int(math.sqrt(n)):ifn%i==0:print(n,)breakelse:i=i+1else:print(n,)961236=1+2+361000m=1000forainrange(2,m+1):s=aL1=[]foriinrange(1,a):ifa%i==0:s-=iL1.append(i)ifs==0:print(%d%a,end=)forjinrange(1,len(L1)):0print(%d%L1[j],end=,)print(\n)1010day=9x=1whileday0:x=(x+1)*2day-=1print(total=,x)1.temp.txt2014310316flname=temp.txtf=open(flname)ht=(f.readline()).strip()L1=list(ht.split(','))lt=(f.readline()).strip()L2=list(lt.split(','))f.close()foriinrange(len(L1)):L1[i]=int(L1[i])L2[i]=int(L2[i])maxVal=L1[0]max.(L1)maxDay=0minVal=L2[0]minDay=0foriinrange(1,len(L1)):ifL1[i]maxVal:maxVal=L1[i]maxDay=iifL2[i]minVal:minVal=L2[i]minDay=iprint(+str(maxDay+1)++str(maxVal)+)print(+str(minDay+1)++str(minVal)+)2510flname=temp.txtf=open(flname)ht=(f.readline()).strip()L1=list(ht.split(','))lt=(f.readline()).strip()L2=list(lt.split(','))f.close()L3=[]foriinrange(len(L1)):L1[i]=int(L1[i])L2[i]=int(L2[i])L3.append(int((L1[i]+L2[i])/2))sum=0k=0foriinrange(len(L3)):sum=sum+L3[i]ifL3[i]=10:k+=1else:k=0avg=int(sum/len(L3))print(,avg)ifk=5:print()else:print()3score1.txt40%60%score2.txt9080897079606960f=open(score1.txt)a=f.readline()line=(f.readline()).strip()f2=open(score2.txt,'w')f2.write(\n);L2=[0,0,0,0,0]count=0sum=0while(len(line)!=0):#print(line)L1=line.split()f2.write(L1[0]+)f_score=int(int(L1[1])*0.4+int(L1[2])*0.6)if90f_score=100:L2[0]+=1eliff_score=80:L2[1]+=1eliff_score=70:L2[2]+=1eliff_score=60:L2[3]+=1else:L2[4]+=1count+=1sum+=f_scoref2.write(str(f_score)+\n)line=(f.readline()).strip()f.close()f2.close()avg_score=int(sum/count)print(%d,90%d8089%d7079%d6069%d60%d%d%(count,L2[0],L2[1],L2[2],L2[3],L2[4],avg_score))f=open(score1.txt)a=f.readlines()dela[0]L3=[]forlineina:line=line.strip()L1=line.split()f_score=int(int(L1[1])*0.4+int(L1[2])*0.6)L3.append([L1[0],f_score])f.close()c=[0,0,0,0,0]count=0sum=0f2=open(score2.txt,'w')f2.write(\n);forL2inL3:if90L2[1]=100:c[0]+=1elifL2[1]=80:c[1]+=1elifL2[1]=70:c[2]+=1elifL2[1]=60:c[3]+=1else:c[4]+=1count+=1sum+=L2[1]f2.write(L2[0]++str(L2[1])+\n)f2.close()avg_score=int(sum/count)print(%d,90%d8089%d7079%d6069%d60%d%d%(count,c[0],c[1],c[2],c[3],c[4],avg_score))4sample12.txtsample12_copy.txtf=open(sample12.txt)L1=f.readlines()f2=open(sample12_copy.txt,'w')forlineinL1:f2.write(line.upper())f.close()f2.close()5class_score.txt2311260390defoutput_avg(L):sum1,sum2=0,0forlineinL:L1=line.strip().split()sum1+=int(L1[1])sum2+=int(L1[2])count=len(L)avg1=round(sum1/count,1)avg2=round(sum2/count,1)print(%4.1f%4.1f%(avg1,avg2))defoutput_notpass(L):print()forlineinL:L1=line.strip().split()ifint(L1[1])60andint(L1[2])60:print(line)defoutput_good(L):print(90)forlineinL:L1=line.strip().split()f_score=round((int(L1[1])+int(L1[2]))/2)iff_score=90:print(line)f=open(class_score.txt)L=f.readlines()delL[0]output_avg(L)output_notpass(L)output_good(L)1.defbubble(List):num=len(List)foriinrange(0,num-1):forjinrange(i+1,num):#ifList[i]List[j]:List[i],List[j]=List[j],List[i]returnListL1=[]num_str=input('')whilelen(num_str)!=0:L1.append(int(num_str))num_str=input('')print(':',bubble(L1))defbubble(List):foriinrange(0,len(List)-1):forjinrange(len(List)-1,i,-1):ifList[j-1]List[j]:List[j-1],List[j]=List[j],List[j-1]returnListL1=[]num_str=input('')whilelen(num_str)!=0:L1.append(int(num_str))num_str=input('')print(':',bubble(L1))2score2.txtf=open(score2.txt)a=f.readlines()dela[0]L2=[]L3=[]forlineina:line=line.strip()L1=line.split()L2.append(L1[0])L3.append(L1[1])f.close()maxScore=L3[0]maxIndex=0minScore=L3[0]minIndex=0foriinrange(1,len(L3)):ifL3[i]maxScore:maxScore=L3[i]maxIndex=iifL3[i]minScore:minScore=L3[i]minIndex=iprint(+str(maxScore)++str(L2[maxIndex]))print(+str(minScore)++str(L2[minIndex]))3letters,space,digit,other=0,0,0,0s=input()foriinrange(len(s)):if(s[i]='a'ands[i]='z')or(s[i]='A'ands[i]='Z'):letters+=1elifs[i]=='':space+=1elifs[i]='0'ands[i]='9':di
本文标题:《Python程序设计》题库
链接地址:https://www.777doc.com/doc-3146804 .html