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))
#
# a=[1,2,3,5,4,3,32,2]
# b=a[:]
# print(b)
#
# for i in range(1,10):
# for j in range(1,i+1):
# print("%d * %d = %d "%(i,j,j*i),end="")
# print()
#
# import time
# time.sleep(1)
# print("s")
#
# 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())))
#
# def f(a):
# if a==1 or a==2:
# return 1
# else:
# return f(a-1)+f(a-2)
# print(f(11))
#
# 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()
#
# 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()
#
# 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)
#
# def f():
# a=float(input("输入成绩:"))
# if 90<=a<=100:
# print("成绩是:A")
# elif 70<=a<90:
# print("成绩是:B")
# else:
# print("成绩是:C")
# f()
#
# import time
# a=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))
# print(a)
#
# 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()
#
# 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)
#
# 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()
#
# def high(n):
# h=100
# n_high=100/(2**(n))
# print(n_high)
# high(10)
#
# num=1
# for i in range(1,10):
# num=2*(num+1)
# print(num)
#
# 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()
#
# 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()
#
# 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()
#
# def f(n):
# if n==1:
# return 1
# else:
# return n*f(n-1)
# print(f(5))
#
# 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)
#
# def f(n):
# if n==1:
# return 10
# else:
# return 2+f(n-1)
# print(f(5))
#
# 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()
#
# 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()
#
# 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()
#
# 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()
#
# a=[1,2,3]
# print("_".join(str(x) for x in a))
#
# def func1():
# print("这是函数1")
# def func2():
# func1()
# print("这是函数2")
# func2()
#
#
# 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()
#
# 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()
#
# 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_)
#
# 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()
#
# def f():
# a=tuple(input("输入:"))
# len_a=len(a)
# for i in range(len_a):
# print(a[len_a-1-i],end="")
# f()
#
# 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()
#
# num=2
# def f():
# num=1
# print("局域:",num)
# num+=1
# for i in range(3):
# f()
# num+=1
# print("全局",num)
#
# 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()
#
# 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)
#
# a=[i for i in range(1,101)]
# print(sum(a))
# def f(n):
# print((n*(n+1)/2))
# f(100)
#
# while True:
# a=int(input("输入某数:"))
# if a**2<=50:
# break
# else:
# print("和:",a**2)
#
# def f():
# a=input("一:")
# b=input("二:")
# c=a
# a=b
# b=c
# print("一:",a)
# print("二:",b)
# f()
#
# 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()
#
# 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))
#
# import random
# a_rand=random.randint(0,19)
# print(a_rand)
#
#位运算符,按照二进制进行计算
#
#
#
#
#
#
#
#
# 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()
#
# def f():
# k=0
# str_=input("输入:")
# print(len(str_))
# for i in str_:
# k+=1
# print(k)
# f()
#
# 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) #
# def f():
# a=input("字符串1:")
# b=input("字符串2:")
# print(a.find(b))
# f()
#
#
#
#
# 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()
#
# 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()
#
# 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)
#
# 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)
#
# if __name__=="__main__":
# a=input("输入:")
# print(len(a))
#
# 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)
#
# def f():
# c=[]
# for i in range(3):
# a=int(input("输入:"))
# c.append(a)
# print(c)
# f()
#
# def f():
# a=input("输入")
# len_a=len(a)
# for i in range(len_a):
# print(a[len_a-i-1],end="")
# f()
#
# def f():
# a=list(input("输入:"))
# b=list(input("输入:"))
# a.sort()
# b.sort()
# print(a+b)
# f()
#
# 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)
#
# 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)
#
# def f():
# a=list(input())
# for i in a:
# print(i,end="")
# f()
#
# 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}}
#
# 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()
#
# 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()
#
# 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)
#
# 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()
#
# def f(a):
# c=[]
# for i in range(a):
# b=input("")
# c.append(b)
# print("--".join(c))
# f(3)
#
# 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()
#
# def f():
# a=input("字符串:")
# b = input("字符串:")
# print("{}-{}".format(a,b))
# print(a+b)
# print("-".join(a))
# f()
#
# 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)
#
# a=int(input("一:"))
# print(a*"*")
#
# 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()
#
# list.append()
# list.extend([])
# list.insert(index,num)
# list.remove()
# list.pop()
# del list()
# list.index()
# list.count()
# list.sort()
# sorted(list,lambda x:)
#
#time模块
#
# import time
# def f():
# start=time.time()
# time.sleep(1)
# end=time.time()
# print(end-start)
# f()
#
#
#
#
# def f():
# a=input()
# b=input()
# print(a.count(b))
# f()
#
# def f():
# a=input()
# for i in a:
# if i!="#":
# print(i,end="")
# else:
# break
# f()
#
# def f():
# a=input()
# a=a.upper()
# with open(r"C:\Users\Administrator\Desktop\1.txt","w") as f:
# f.write(a)
# f()
#
# with open (r"C:\Users\Administrator\Desktop\1.txt","r") as f1:
# cont1=f1.read()
# with open(r"C:\Users\Administrator\Desktop\2.txt", "r") as f2:
# cont2=f2.read()
# l=list(cont1+cont2)
# l.sort()
# print(l)
# s="-".join(l)
# print(s)
# with open(r"C:\Users\Administrator\Desktop\3.txt", "w") as f3:
# f3.write(str(s)) #
# 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)
上一篇:http数据返回值


下一篇:HTML5 canvas 中的线条样式