L = []
n=1
while True:
L.append(n*n)
n=n+1
if n>100:
break
print sum(L)
n=1
while True:
L.append(n*n)
n=n+1
if n>100:
break
print sum(L)
2019-10-27
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
2019-10-27
d={'Adam':95,'Lisa':85,'Bart':59}
for dic in d:
print (dic,':',d.get(dic))
for dic in d:
print (dic,':',d.get(dic))
2019-10-27
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
name = x[0]
score = x[1]
print name ,':',score
for x in s:
name = x[0]
score = x[1]
print name ,':',score
2019-10-26
def average(*args):
if len(args)== 0:
return '0.0'
else:
return float(sum(args))/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args)== 0:
return '0.0'
else:
return float(sum(args))/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2019-10-25
用Python3答案:print (u'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。''')
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。''')
2019-10-23
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 +y
for y in ['0' '1','2','3','4','5','6','7','8','9' ]:
if x<y:
print x +y
2019-10-23
def greet(z='world'):
if z==None:
print("Hello,world.")
else:
print("Hello,"+z+".")
greet()
greet('Bart')
if z==None:
print("Hello,world.")
else:
print("Hello,"+z+".")
greet()
greet('Bart')
2019-10-20
x1 = 1
d = 3
n = 100
x100 = x1+(n-1)*d
s =n*(x1+x100)/2
print s
d = 3
n = 100
x100 = x1+(n-1)*d
s =n*(x1+x100)/2
print s
2019-10-20
sum = 0
x = 1
n = 1
while True:
sum=x+sum
x=2*n(此处n的变化甚小)
n=n+1
if n>20:
break
print sum
记录错误……
x = 1
n = 1
while True:
sum=x+sum
x=2*n(此处n的变化甚小)
n=n+1
if n>20:
break
print sum
记录错误……
2019-10-18