python3不能用答案的内容,我只好用以下的内容
s1=[]
s2=[]
s3=[]
for i in range(1,101):
if i<=10:
s1.append(i)
if i%3==0:
s2.append(i)
if i%5==0:
if i<50:
s3.append(i)
print(s1)
print(s2)
print(s3)
s1=[]
s2=[]
s3=[]
for i in range(1,101):
if i<=10:
s1.append(i)
if i%3==0:
s2.append(i)
if i%5==0:
if i<50:
s3.append(i)
print(s1)
print(s2)
print(s3)
2018-11-25
x1 = 1
d = 3
n = 0
x100 = 0
s = 0
while n < 100:
s = s + x1
x1 = x1 + d
n = n + 1
print s
要用循环
d = 3
n = 0
x100 = 0
s = 0
while n < 100:
s = s + x1
x1 = x1 + d
n = n + 1
print s
要用循环
2018-11-24
def square_of_sum(L):
sum=0
for i in L:
sum+=i*i
return sum
print(square_of_sum([1, 2, 3, 4, 5]))
print(square_of_sum([-5, 0, 5, 15, 25]))
sum=0
for i in L:
sum+=i*i
return sum
print(square_of_sum([1, 2, 3, 4, 5]))
print(square_of_sum([-5, 0, 5, 15, 25]))
2018-11-23
sum =1
x = 1
#或者sum=0 x=0
while True:
x+=1
if x > 100:
break
else:
if x%2 == 0:
continue
sum+=x
print(sum)
x = 1
#或者sum=0 x=0
while True:
x+=1
if x > 100:
break
else:
if x%2 == 0:
continue
sum+=x
print(sum)
2018-11-23
sum = 0
x = 1
while True:
sum+=x
x = x + 2
if x > 100:
break
print sum
都是加奇数,而且没要求多严谨,所以之间X+2就可以了
x = 1
while True:
sum+=x
x = x + 2
if x > 100:
break
print sum
都是加奇数,而且没要求多严谨,所以之间X+2就可以了
2018-11-23
age = 2
if 18 > age >= 6:
print 'teenager'
elif age >= 18:
print 'adult'
else:
print 'kid'
if 18 > age >= 6:
print 'teenager'
elif age >= 18:
print 'adult'
else:
print 'kid'
2018-11-22
两重:
print [int(m+n+m) for m in '123456789' for n in '0123456789']
print [int(m+n+m) for m in '123456789' for n in '0123456789']
2018-11-21
def average(*args):
sum=0.0
if len(args)>0:
for x in args:
sum+=x
return sum/len(args)
else:
return sum
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
没问题吧
sum=0.0
if len(args)>0:
for x in args:
sum+=x
return sum/len(args)
else:
return sum
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
没问题吧
2018-11-21
个人觉得因为第一遍的时候POP已经删掉了Paul,那么Bart的索引号应该变成2而不是3了,所以L.pop(2)L.pop(2)才对
2018-11-20
print [x1*100+x2*10+x3 for x1 in range(1,10) for x2 in range(0,10) for x3 in range(1,10) if x1 == x3]
2018-11-20