pi = 0 n = 100 for k in range(n): pi+=1/pow(16,k)*( #一行不够写或不易读时用\,则多行与一行一样 4/(8*k+1)-2/(8*k+4)- 1/(8*k+5) -1/(8*k+6)) print("圆周率: {}".format(pi))
输入
a,b = input().split() a+=b print(a) 6 -5 6-5 a,b,c=map(eval,input().split()) a+=b print(a,c) 0.3 1.5 6 1.8 6
循环
list_of_lists = [range(4), range(7)] flattened_list = [] #flatten the lis for x in list_of_lists: for y in x: flattened_list.append(y)
0 1 2 3 0 1 2 3 4 5 6
list = [range(4),range(7)] flattened = [y for x in list for y in x] print(flattened)
[0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6]