def greet(world = 'world'):
print 'Hello' + ' '+ world
greet()
greet('Bart')
print 'Hello' + ' '+ world
greet()
greet('Bart')
2015-10-03
def quadratic_equation(a, b, c):
temp = b**2 - 4*a*c
if temp < 0:
print '德尔塔小于零'
else:
x = (-b - math.sqrt(b**2 -4*a*c ))/(2*a)
y = (-b + math.sqrt(b**2 -4*a*c ))/(2*a)
return y,x
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
temp = b**2 - 4*a*c
if temp < 0:
print '德尔塔小于零'
else:
x = (-b - math.sqrt(b**2 -4*a*c ))/(2*a)
y = (-b + math.sqrt(b**2 -4*a*c ))/(2*a)
return y,x
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2015-10-03
def square_of_sum(L):
sum = 0
for i in L:
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 += i*i
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-10-03
L = []
for i in range(1,101):
ii = i*i
L.append(ii)
print sum(L)
for i in range(1,101):
ii = i*i
L.append(ii)
print sum(L)
2015-10-03
s = set(['Adam', 'Lisa', 'Bart', 'Paul'])
ss = set()
for i in s:
i = i.lower()
ss.add(i)
print 'adam' in ss
print 'bart' in ss
ss = set()
for i in s:
i = i.lower()
ss.add(i)
print 'adam' in ss
print 'bart' in ss
2015-10-03
for x in range(1,10):
for y in range(0,10):
if x<y:
print '%s%s'%(x,y)
for y in range(0,10):
if x<y:
print '%s%s'%(x,y)
2015-10-03
sum = 0
x = 1
while True:
x = x + 1
if x %2 == 0:
continue
else:
print x
sum += x
if x >= 99:
sum += 1
break
print sum
x = 1
while True:
x = x + 1
if x %2 == 0:
continue
else:
print x
sum += x
if x >= 99:
sum += 1
break
print sum
2015-10-03
sum = 0
x = 1
n = 1
while True:
sum += 2**n
if n == 20:
sum += 1
break
print sum
x = 1
n = 1
while True:
sum += 2**n
if n == 20:
sum += 1
break
print sum
2015-10-03
score = 55
if score >= 60:
print "passed"
else:
print "failed"
if score >= 60:
print "passed"
else:
print "failed"
2015-10-02
L = ['Adam', 'Lisa', 'Bart']
L.insert(2,'Pual')
print L
L.insert(2,'Pual')
print L
2015-10-02
L = [95.5, 85, 59]
print L[0]
print L[1]
print L[2]
木有第四个 老师出错了吧
print L[0]
print L[1]
print L[2]
木有第四个 老师出错了吧
2015-10-02