Python-100道练习题答案
Posted python-t
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python-100道练习题答案相关的知识,希望对你有一定的参考价值。
题目链接:http://www.runoob.com/python/python-100-examples.html
#5. # def find_max(): # a=int(input("输入:")) # b = int(input("输入:")) # c = int(input("输入:")) # list_=[a,b,c] # print(list_) # list_.sort() # find_max() #6. # def f(a): # if a==1 or a==2: # flag=-1 # return 1 # else: # return f(a-2)+f(a-1) # print(f(12)) # for i in range(1,13): # print(f(i)) #7 # a=[1,2,3,5,4,3,32,2] # b=a[:] # print(b) #8 # for i in range(1,10): # for j in range(1,i+1): # print("%d * %d = %d "%(i,j,j*i),end="") # print() #9 # import time # time.sleep(1) # print("s") #10 # import time # print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))) # time.sleep(1) # print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))) #11 # def f(a): # if a==1 or a==2: # return 1 # else: # return f(a-1)+f(a-2) # print(f(11)) #12 # import math # def sushu(): # a=[x for x in range(100,201)] # for i in a: # flag = 1 # b=int(math.sqrt(i // 2 + 1))+1 # for j in range(2,b): # if i%j==0: # flag=-1 # break # if flag==1: # print(i) # sushu() #13 # def f(): # for i in range(100,1000): # b=i//100 # s=i//10%10 # g=i%10 # if b**3+s**3+g**3==i: # print(i) # f() #14 # import math # def f(a): # print("{}=".format(a),end="") # c=[] # i=2 # while i <=a: # if a%i==0: # c.append(i) # a=a/i # print("{}*".format(i),end="") # i=2 # else: # i+=1 # f(100) #15 # def f(): # a=float(input("输入成绩:")) # if 90<=a<=100: # print("成绩是:A") # elif 70<=a<90: # print("成绩是:B") # else: # print("成绩是:C") # f() #16 # import time # a=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time())) # print(a) #17 # def f(): # space=0 # digit=0 # alpha=0 # other=0 # a=input("输入任意内容") # a=list(a) # for i in a: # if i.isspace(): # space+=1 # elif i.isalpha(): # alpha+=1 # elif i.isdigit(): # digit+=1 # else: # other+=1 # print("字母是%d个,数字是%d个,空格是%d个,其他是%d个"%(alpha,digit,space,other)) # f() #18 # def f(a,num): # sum_a_num=0 # if num==0: # print("0") # else: # for i in range(num): # for j in range(-1,i): # print(a,end="") # print() # print(sum_a_num) # f(2,5) # def f(a,num): # c=[] # t=0 # if num==0: # print("0") # else: # for i in range(num): # t=t+a # a=a*10 # print(t) # c.append(t) # print(sum(c)) # f(2,5) #19 # def f(): # for i in range(2,1001): # c = [] # for j in range(1,i//2+1): # if i%j==0: # c.append(j) # if sum(c)==i: # for k in c: # print(k,end=",") # print() # print(i) # f() #20 # def high(n): # h=100 # n_high=100/(2**(n)) # print(n_high) # high(10) #21 # num=1 # for i in range(1,10): # num=2*(num+1) # print(num) #22 # def f(): # jia="abc" # yi="xyz" # for i in jia: # for j in yi: # if (i=="a" and j=="x") or (i=="c" and j=="x" )or (i=="c" and j=="z" ): # print(i,j) # f() # #23 # for i in range(1,4): # for j in range(1,4-i): # print(" ",end="") # for k in range(1,2*i+1-1): # print("*",end="") # print() # for i in range(1,3): # for j in range(1,i+1): # print(" ",end="") # for k in range(1,2*(3-i)+1-1): # print("*",end="") # print() #24 # def f(): # i=2 # j=1 # a=0 # for x in range(10): # a = i / j # b=j # j = i # i = i + b # # a+=a # print(a) # f() #25 # def f(): # sum_=0 # for i in range(1,21): # s=1 # for j in range(1,i+1): # s=s*j # sum_+=s # print(sum_) # f() #26 # def f(n): # if n==1: # return 1 # else: # return n*f(n-1) # print(f(5)) #27 # def f(a,b): # if b>=1: # print(a[b-1],end="") # return f(a,b-1) # else: # exit() # str_=input("字符串:") # len_str=len(str_) # f(str_,len_str) #28 # def f(n): # if n==1: # return 10 # else: # return 2+f(n-1) # print(f(5)) #29 # def f(): # a=int(input("输入数字")) # b=str(a) # len_a=len(b) # print("长度是:",len_a) # for i in range(len_a): # print(b[len_a-i-1],end="") # f() #30 # def f(): # a=input("输入:") # len_a=len(a) # len_a2=len(a)//2 # for i in range(len_a2): # flag = 1 # if a[len_a-i-1]!=a[i]: # print("不是回文") # flag=-1 # break # if flag==1: # print("回文") # f() #31 # def f(): # a=input("输入:") # if a[0].lower()=="w": # print("星期三") # elif a[0].lower()=="m": # print("星期一") # elif a[0].lower()=="f": # print("星期五") # elif a[0].lower()=="t": # if a[1].lower()=="h": # print("星期四") # else: # print("星期二") # elif a[0].lower()=="s": # if a[1].lower()=="a": # print("星期六") # else: # print("星期日") # f() #32 # def f(): # a=input("输入:") # a=list(a) # lena=len(a) # len_a=len(a)-1 # for i in range(lena): # print(a[len_a-i],end="") # f() #33 # a=[1,2,3] # print("_".join(str(x) for x in a)) #34 # def func1(): # print("这是函数1") # def func2(): # func1() # print("这是函数2") # func2() #35 #36 # import math # def f(): # a=[i for i in range(1,101)] # print(a) # for k in range(4,101): # b=int(math.sqrt(k))+1 # print(b) # for j in range(2,b): # if k%j==0: # a.remove(k) # break # print(a) # f() #37 # def f(): # a=list(input("输入数字:")) # print(a) # len_a=len(a) # for i in range(len_a): # for j in range(i+1,len_a): # if a[i]<=a[j]: # k=a[i] # a[i]=a[j] # a[j]=k # print(" ".join(a)) # f() #38 # a=[] # for i in range(0,4): # b=[] # for j in range(1,5): # b.append(i+j) # a.append(b) # print(a) # len_a=len(a) # len_a_=len(a[0]) # sum_=0 # for i in range(len_a): # for j in range(len_a_): # if i==j: # sum_+=a[i][j] # print(sum_) #39 # def f(): # a=list(input("输入:")) # len_a=len(a) # for i in range(len_a): # for j in range(i+1,len_a): # if a[i]<=a[j]: # k=a[i] # a[i]=a[j] # a[j]=k # print(a) # print(" ".join(a)) # b=input("输入一个数:") # for i in range(len_a): # if int(b)>=int(a[i]): # a.insert(i,b) # break # print(" ".join(a)) # f() #40 # def f(): # a=tuple(input("输入:")) # len_a=len(a) # for i in range(len_a): # print(a[len_a-1-i],end="") # f() #41 # def f(): # var=0 # print("var是:",var) # var+=1 # for i in range(3): # f() # class A(): # var=0 # def f(self): # self.var+=1 # print("var是:",self.var) # a=A() # for i in range(3): # a.f() #42 # num=2 # def f(): # num=1 # print("局域:",num) # num+=1 # for i in range(3): # f() # num+=1 # print("全局",num) #43 # class A(): # var=1 # def f(self): # self.var+=1 # print("属性是:",self.var) # a=A() # var1=9 # for i in range(3): # var1 += 1 # print("变量是:",var1) # a.f() #44 # x = [[12,7,3], # [4 ,5,6], # [7 ,8,9]] # # y= [[5,8,1], # [6,7,3], # [4,5,9]] # c=[] # for i in range(3): # b=[] # for j in range(3): # b.append(x[i][j]+y[i][j]) # c.append(b) # print(c) #45 # a=[i for i in range(1,101)] # print(sum(a)) # def f(n): # print((n*(n+1)/2)) # f(100) #46 # while True: # a=int(input("输入某数:")) # if a**2<=50: # break # else: # print("和:",a**2) #47 # def f(): # a=input("一:") # b=input("二:") # c=a # a=b # b=c # print("一:",a) # print("二:",b) # f() #48 # def f(): # a=int(input("一:")) # b=int(input("二:")) # if a==b: # print("%d=%d"%(a,b)) # elif a>b: # print("%d>%d"%(a,b)) # else: # print("%d<%d"%(a,b)) # f() #49 # a=[lambda:[x for x in range(10)]] # b=[x for x in range(10)] # list2=[1,4,6,-3,-9,-2] # print(sorted(c,key=lambda x:abs(x))) # print(list(map(lambda x:x+1,c))) # print(list(filter(lambda x: x%2==0,c))) # print(sorted(c,key=lambda x:x["time"])) # def f(a,b): # return lambda x:a*x+b # z=f(3,3) # print(z(4)) #50 # import random # a_rand=random.randint(0,19) # print(a_rand) #51 #位运算符,按照二进制进行计算 #52 #53 #54 #55 #56 #57 #58 #59 # def f(): # for i in range(100,1000): # i_3=i//100 # i_2=i//10%10 # i_1=i%10 # print("{},{},{}".format(i_3,i_2,i_1)) # f() #60 # def f(): # k=0 # str_=input("输入:") # print(len(str_)) # for i in str_: # k+=1 # print(k) # f() #61 # b=[[1],] # for i in range(0,5): # c=[] # for j in range(0,i+1): # if j==0: # c.append(b[i][j]) # if j<=i-1: # c.append(b[i][j]+b[i][j+1]) # c.append(1) # b.append(c) # print(b) # for i in b: # for k in i: # print(k,end=" ") # print() # print(b) # b=[] # for i in range(0,5): # c=[] # for j in range(0,i): # if j==0: # c.append(b[i-1][j]) # if j<=i-2: # c.append(b[i-1][j]+b[i-1][j+1]) # c.append(1) # b.append(c) # print(b) # for i in b: # for k in i: # print(k,end=" ") # print() # print(b) #62 # def f(): # a=input("字符串1:") # b=input("字符串2:") # print(a.find(b)) # f() #63 #64 #65 #66 # def f(): # d=[] # a=int(input("a:")) # b=int(input("b:")) # c=int(input("c:")) # d.extend([a,b,c]) # d.sort(reverse=True) # print(d) # f() #67 # def f(): # c=[] # for i in range(6): # a=int(input("输入数字:")) # c.append(a) # c1 = c # print(c) # for i_1 in range(6): # for i_2 in range(i_1,6): # if c1[i_1]<=c1[i_2]: # k=c1[i_1] # c1[i_1]=c1[i_2] # c1[i_2]=k # max_=c.index(c1[0]) # min_=c.index(c1[5]) # max_1=c[0] # c[0]=c[max_] # c[max_]=max_1 # # min_1 = c[5] # c[5] = c[min_] # c[min_] = min_1 # print(c) # f() #68 # def f(m,n): # c=[] # b=[] # for i in range(m): # a=input("输入:") # c.append(a) # for i in range(n,m): # b.append(c[i]) # for i in range(n): # b.append(c[i]) # print(b) # f(8,4) #69 # def people_3(a): # j=0 # list_a=[x for x in range(1,a+1)] # i=0 # while i<len(list_a): # j+=1 # if j==3: # list_a.remove(list_a[i]) # j=0 # i-=1 # if i==len(list_a)-1: # i=-1 # i+=1 # if len(list_a)==1: # print(list_a) # break # people_3(4) #70 # if __name__=="__main__": # a=input("输入:") # print(len(a)) # 71 # d = {} # def write(): # print(type(d)) # for i in range(5-len(d)): # a=input("输入键名:") # if a == "0": # break # b=input("输入键值:") # # d.update({a:b}) # d.update([(a,b)]) # print(d) # def read(): # a = input("输入键名:") # for key,value in d.items(): # if a==key: # print(key,":",value) # write() # read() # a={"q":1,"w":"2"} # for key,value in a.items(): # if "w"==key: # print(key,":",value) #72 # def f(): # c=[] # for i in range(3): # a=int(input("输入:")) # c.append(a) # print(c) # f() #73 # def f(): # a=input("输入") # len_a=len(a) # for i in range(len_a): # print(a[len_a-i-1],end="") # f() #74 # def f(): # a=list(input("输入:")) # b=list(input("输入:")) # a.sort() # b.sort() # print(a+b) # f() #75 # for i in range(5): # n = 0 # if i != 1: n += 1 # if i == 3: n += 1 # if i == 4: n += 1 # if i != 4: n += 1 # if n == 3: print(64 + i) #76 # def f(a): # sum_a=0 # if a%2==0: # for i in range(1,a//2+1): # sum_a+=(1/(2*i)) # else: # for i in range(1,a//2+1): # sum_a+=1/2*i+1 # print(sum_a) # f(6) #77 # def f(): # a=list(input()) # for i in a: # print(i,end="") # f() #78 # def f(): # dic={‘a‘:1,‘f‘:2,‘c‘:3,‘h‘:0} # sorted(dic.items(),key=lambda x:x[1]) # print(dic) # f() # a={"001":{"name":"张三","age":12}, # "002":{"name":"李四","age":22}, # "003": {"name": "王二", "age": 19}} #79 # def f(): # a=input("") # b=input("") # c=input("") # if a>b : a,b=b,a # if a>c: a,c=c,a # if b>c: b,c=c,b # print(a,b,c) # f() #80 # def f(): # for i in range(3120,4000): # flag = 1 # k=i # for j in range(5): # if i%5==1: # i=(i//5)*4 # else: # flag=-1 # break # if flag==1: # print(k) # f() #81: # def f(): # a=809 # for i in range(10,100): # if (a*i==800*i+9*i) and (9000<a*i<10000): # print(a*i) # f() #82 # def f(a): # c=[] # while True: # x1=a//8 # x2=a%8 # c.append(x2) # a=x1 # if x1<8: # c.append(x1) # break # for i in range(len(c)): # print(c[len(c)-i-1],end="") # f(28) #83 # def f(): # for i in range(0,7): # if i==0: # print("4") # elif i == 1: # print("28") # else: # print(7*(8**(i-1))*4) # f() #84 # def f(a): # c=[] # for i in range(a): # b=input("") # c.append(b) # print("--".join(c)) # f(3) #85 # def f(): # a=int(input("输入奇数:")) # for i in range(1,10): # z = 0 # for j in range(0,i): # z+=9*(10**j) # # print(z) # if z%a==0: # print(z) # break # f() #86 # def f(): # a=input("字符串:") # b = input("字符串:") # print("{}-{}".format(a,b)) # print(a+b) # print("-".join(a)) # f() #87 # class A(): # var=1 # var2="a" # def f(self,c): # c.var=3 # c.var2="c" # a=A() # a.var=10 # a.var2="asd" # a.f(a) # print(a.var) # print(a.var2) #88 # a=int(input("一:")) # print(a*"*") #89 # def f(): # a=input("") # a=list(a) # c=[] # for i in a: # i=(int(i)+5)%10 # c.append(i) # print(c) # c[0],c[3]=c[3],c[0] # c[1],c[2]=c[2],c[1] # print(c) # f() #90 # list.append() # list.extend([]) # list.insert(index,num) # list.remove() # list.pop() # del list() # list.index() # list.count() # list.sort() # sorted(list,lambda x:) #91 #time模块 #92 # import time # def f(): # start=time.time() # time.sleep(1) # end=time.time() # print(end-start) # f() #93 #94 #95 #96 # def f(): # a=input() # b=input() # print(a.count(b)) # f() #97 # def f(): # a=input() # for i in a: # if i!="#": # print(i,end="") # else: # break # f() #98 # def f(): # a=input() # a=a.upper() # with open(r"C:UsersAdministratorDesktop1.txt","w") as f: # f.write(a) # f() #99 # with open (r"C:UsersAdministratorDesktop1.txt","r") as f1: # cont1=f1.read() # with open(r"C:UsersAdministratorDesktop2.txt", "r") as f2: # cont2=f2.read() # l=list(cont1+cont2) # l.sort() # print(l) # s="-".join(l) # print(s) # with open(r"C:UsersAdministratorDesktop3.txt", "w") as f3: # f3.write(str(s)) #100 # def f(): # a=list(input()) # b=list(input()) # c=dict(zip(a,b)) # print(c) # f() # i = [‘a‘, ‘b‘] # l = [1, 2] # a=dict([i,l]) # print (a)
以上是关于Python-100道练习题答案的主要内容,如果未能解决你的问题,请参考以下文章