在Python3上,是这样运行的:
print ('静夜思\n床前明月光,\n疑是地上霜。\n举头望明月,\n低头思故乡。')
print ('静夜思\n床前明月光,\n疑是地上霜。\n举头望明月,\n低头思故乡。')
2016-01-04
难道if就差一个括号吗?这个括号就这么重要吗?
for x in [ 1,2,3,4,5,6,7,8,9 ]:
for y in [ 0,1,2,3,4,5,6,7,8,9 ]:
if (x<y):
print x*10 + y
for x in [ 1,2,3,4,5,6,7,8,9 ]:
for y in [ 0,1,2,3,4,5,6,7,8,9 ]:
if (x<y):
print x*10 + y
2016-01-04
l = [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]
n = []
for i in l:
a = int(i)
n.append(a)
print n
n = []
for i in l:
a = int(i)
n.append(a)
print n
2016-01-03
def square_of_sum(L):
sum = 0
for i in L:
sum = 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 = sum + i*i
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2016-01-03
L = [75, 92, 59, 68]
sum = 0.0
for i in range(len(L)):
sum += L[i]
print sum / len(L)
sum = 0.0
for i in range(len(L)):
sum += L[i]
print sum / len(L)
2016-01-03
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for i in L:
if i in s:
s.remove(i)
else:
s.add(i)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for i in L:
if i in s:
s.remove(i)
else:
s.add(i)
print s
2016-01-03
for x in ['1','2','3','4','5','6','7','8','9']:
for y in ['1','2','3','4','5','6','7','8','9']:
if x < y:
print x + y
for y in ['1','2','3','4','5','6','7','8','9']:
if x < y:
print x + y
2016-01-03
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
sum = sum + x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
sum = sum + x
print sum
2016-01-03
def square_of_sum(list):
sum = 0
for x in list:
sum += x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum = 0
for x in list:
sum += x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2016-01-03
擦,原来答案是手动添加小写名字啊?
另外,代码正确与否不是看结果而是直接对比代码语句啊?否则为什么我使用双引号就一直提示错误,而更换单引号就通过了呢?
另外,代码正确与否不是看结果而是直接对比代码语句啊?否则为什么我使用双引号就一直提示错误,而更换单引号就通过了呢?
2016-01-03
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(3)
L.pop(2)
print L
这样也可以啊
L.pop(3)
L.pop(2)
print L
这样也可以啊
2016-01-03