def square_of_sum(L):
sum = 0
for x in L:
x = x * x
sum = sum + 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 L:
x = x * x
sum = sum + x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-12-01
x = 1
sum = 0
while x <= 100:
sum = sum + x * x
x = x + 1
print sum
sum = 0
while x <= 100:
sum = sum + x * x
x = x + 1
print sum
2015-12-01
x = 1
sum = 0
while x <= 100:
sum = sum + x * x
x = x + 1
print sum
sum = 0
while x <= 100:
sum = sum + x * x
x = x + 1
print sum
2015-12-01
sum = 0
x = 1
n = 1
while True :
sum = sum + (x+1)**(n-1)
n = n + 1
if n > 20 :
break
print sum
简化后就是下面写的代码
x = 1
n = 1
while True :
sum = sum + (x+1)**(n-1)
n = n + 1
if n > 20 :
break
print sum
简化后就是下面写的代码
2015-11-30
sum = 0
n = 0
while True:
sum = sum + 2**n
n = n + 1
if n > 19:
break
print sum
n = 0
while True:
sum = sum + 2**n
n = n + 1
if n > 19:
break
print sum
2015-11-30
讲的太好了 我电脑上装的是python3 跟这个python2.x版本的还是有差别的 至少print打印如果按照print 2.x打印会出错,希望这上面教程也更新到3.x版本
2015-11-29
L = ['Adam', 'Lisa', 'Bart']
a='Adam'
L[0]=L[2]
L[2]=a
print L
a='Adam'
L[0]=L[2]
L[2]=a
print L
2015-11-29
正是因为用()定义单元素的tuple有歧义,所以 Python 规定,单元素 tuple 要多加一个逗号“,”,这样就避免了歧义:
2015-11-29
L = [75, 92, 59, 68]
sum = 0.0
for score in L:
sum = sum + score
print sum / len(L)
sum = 0.0
for score in L:
sum = sum + score
print sum / len(L)
2015-11-28