方法一(自创野路子)
L = range(1,101)
time = 100
a=0
for num in L:
sum = num*num
a=a+sum
if time >100:
continue
print a
方法二(参考其他同学)
b = []
for s in range(1,101):
b.append(s*s)
print sum(b)
L = range(1,101)
time = 100
a=0
for num in L:
sum = num*num
a=a+sum
if time >100:
continue
print a
方法二(参考其他同学)
b = []
for s in range(1,101):
b.append(s*s)
print sum(b)
2018-10-27
#coding = utf-8
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key,value in d.items():
print key +':' + str(value)
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key,value in d.items():
print key +':' + str(value)
2018-10-27
#coding = utf-8
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key,value in d.items():
value = str(value)
print key +':' + value
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key,value in d.items():
value = str(value)
print key +':' + value
2018-10-27
print [str(a)+str(b)+str(c) for a in range(1,10) for b in range(0,10) for c in range(1,10) if a==c]
2018-10-27
def square_of_sum(L):
s=0
for x in L:
s=s+x*x
return s
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
结果
50
900
s=0
for x in L:
s=s+x*x
return s
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
结果
50
900
2018-10-26
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
temp = set(L)
for name in s:
temp.remove(name)
print temp
L = ['Adam', 'Lisa', 'Bart', 'Paul']
temp = set(L)
for name in s:
temp.remove(name)
print temp
2018-10-26
for x in [ '1','2','3','4','5','6','7','8','9']:
for y in [ '2','3','4','5','6','7','8','9']:
if x<y:
print x+y
for y in [ '2','3','4','5','6','7','8','9']:
if x<y:
print x+y
2018-10-26
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print '%s : %d' % x
for x in s:
print '%s : %d' % x
2018-10-25
print [i for i in range(100, 1000) if str(i)[:] == str(i)[::-1] ]
2018-10-25
for x in [ "1","2","3","4","5","6","7","8" ]:
for y in [ "2","3","4","5","6","7","8","9" ]:
if x<y:
print x + y
for y in [ "2","3","4","5","6","7","8","9" ]:
if x<y:
print x + y
2018-10-25
x1=1;
x2=0
d=3;
i=0;
for i in range(1,100):
x2=x1+x2
x1=x1+d
print x1+x2;
x2=0
d=3;
i=0;
for i in range(1,100):
x2=x1+x2
x1=x1+d
print x1+x2;
2018-10-25