L = [95.5,85,59]
print L[0]
print L[1]
print L[2]
print L
过了,第四个就是让我们认识到错误
print L[0]
print L[1]
print L[2]
print L
过了,第四个就是让我们认识到错误
2015-04-25
L = [95.5,85,59]
print L[0]
print L[1]
print L[2]
print L[2]
print L[0]
print L[1]
print L[2]
print L[2]
2015-04-25
def average(*args):
sum = 0
t = float(len(args))
if t == 0 :
return 0.0
else:
for x in args:
sum += x
return sum/t
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
sum = 0
t = float(len(args))
if t == 0 :
return 0.0
else:
for x in args:
sum += x
return sum/t
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-04-24
def square_of_sum(L):
sum = 0
for x in L:
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 L:
sum += x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-04-24
def average(*args):
sum=0.0
for x in args:
sum=sum+x
t=len(args)
if t==0:
return 0.0
else:
return sum/t
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
sum=0.0
for x in args:
sum=sum+x
t=len(args)
if t==0:
return 0.0
else:
return sum/t
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-04-24
import math
def quadratic_equation(a, b, c):
if a==0:
return -c/b
elif b**2-4*a*c>=0:
return (-b+math.sqrt(b**2-4*a*c))/(2*a),(-b -math.sqrt(b**2-4*a*c))/(2*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
if a==0:
return -c/b
elif b**2-4*a*c>=0:
return (-b+math.sqrt(b**2-4*a*c))/(2*a),(-b -math.sqrt(b**2-4*a*c))/(2*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2015-04-24
def greet(x2 = 'world',x1 = 'hello,',x3 ='.'):
print x1,x2,x3
greet()
greet('Bart')
print x1,x2,x3
greet()
greet('Bart')
2015-04-24
各位不要纠结第四个了,这个就是让大家看看程序报错的效果IndexError: list index out of range
2015-04-23
sum = 0
x = 1
n = 1
while True:
sum = sum +x
x = 2 * x
n = n+1
if n> 20:
break
print sum
x = 1
n = 1
while True:
sum = sum +x
x = 2 * x
n = n+1
if n> 20:
break
print sum
2015-04-23