第一种:
L = range(100,1000)
print([m for m in L if str(m)[0] == str(m)[2]])
第二种:
print([m*100+n*10+m for m in range(1,10) for n in range(0,10)])
无需if哦。
L = range(100,1000)
print([m for m in L if str(m)[0] == str(m)[2]])
第二种:
print([m*100+n*10+m for m in range(1,10) for n in range(0,10)])
无需if哦。
2020-06-04
先删除index(2)的话,则下一次python执行操作的时候bart的index即为(2)因此如果运营pop(3)的话则超出list的元素个数界限。将两个顺序颠倒删除即可解决。
2020-06-03
x1 = 1
d = 3
n=100
sum = 0
for x in range(1,n+1):
# print(x,x1)
sum += x1
# print(x,x1,sum)
x1 += d
x100 = x1-d
# print(x100)
s = "sum = {}".format(sum)
print(s)
d = 3
n=100
sum = 0
for x in range(1,n+1):
# print(x,x1)
sum += x1
# print(x,x1,sum)
x1 += d
x100 = x1-d
# print(x100)
s = "sum = {}".format(sum)
print(s)
2020-06-01
x1 = 1
d = 3
n = 100
for x in range(1,n+1):
# print(x,x1)
x1 += d
x100 = x1 - d
s = "x100 = {}".format(x100)
print(s)
d = 3
n = 100
for x in range(1,n+1):
# print(x,x1)
x1 += d
x100 = x1 - d
s = "x100 = {}".format(x100)
print(s)
2020-06-01
import math
def quadratic_equation(a, b, c):
t = math.sqrt(b*b - 4*a*c)
x1 = (-b - t)/(2*a)
x2 = (-b + t)/(2*a)
return x2,x1
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
注意分母2*a,一定得括号括起来,不然程序会认为先÷2,然后×a,结果就错咯
def quadratic_equation(a, b, c):
t = math.sqrt(b*b - 4*a*c)
x1 = (-b - t)/(2*a)
x2 = (-b + t)/(2*a)
return x2,x1
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
注意分母2*a,一定得括号括起来,不然程序会认为先÷2,然后×a,结果就错咯
2020-05-28
def square_of_sum(L):
sum=0
for a in L:
sum+=a**2
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum=0
for a in L:
sum+=a**2
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2020-05-25
我觉得这个网特别好,我们那个年代根本没有这么好的东西。大家免费学习,要有感恩的心。计算机这东西说复杂还是很复杂的,细节问题和版本有很大关系。
2020-05-25