print [m+n+k for m in "123456789" for n in "0123456789" for k in "0123456789" if m==k] 貌似也可以吧??就是出现是字符不是数字
2015-04-23
谁能清楚的解释下这句代码意思? '<tr><td>%s</td><td>%s</td></tr>',另外其中的td、tr、和/td、/tr又有什么不同,为什么是采用<>括号?求扫盲。非常感谢
2015-04-23
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
2015-04-23
print 'name:',k,'score:',d[k]
name: Lisa score: 85
name: Adam score: 95
name: Bart score: 59
输出这么美观都不让过,非要输出那么丑的形式。。。
name: Lisa score: 85
name: Adam score: 95
name: Bart score: 59
输出这么美观都不让过,非要输出那么丑的形式。。。
2015-04-23
这个可以通过
def average(*args):
if sum(args) != 0:
av = float(sum(args)) / float(len(args))
return av
else:
return 0.0
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
def average(*args):
if sum(args) != 0:
av = float(sum(args)) / float(len(args))
return av
else:
return 0.0
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-04-22
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(2)
L.pop()
print L
L.pop(2)
L.pop()
print L
2015-04-22
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(2)
L.pop(2)
print L
L.pop(2)
L.pop(2)
print L
2015-04-22
x1 = 1
d = 3
n = 100
x100 = x1+(n-1)*d
s = (x100+x1)*n/2
print s
d = 3
n = 100
x100 = x1+(n-1)*d
s = (x100+x1)*n/2
print s
2015-04-21
score = 75
if score >= 60:
print "Bart's score is",score
print 'passed'
print 'END'
if score >= 60:
print "Bart's score is",score
print 'passed'
print 'END'
2015-04-21
import math
def quadratic_equation(a, b, c):
det=math.sqrt(b * b - 4 * a * c);
return (-b + det)/(2*a), (-b-det)/(2*a);
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
det=math.sqrt(b * b - 4 * a * c);
return (-b + det)/(2*a), (-b-det)/(2*a);
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2015-04-21