d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
print d.values()
sum = 0.0
for v in d.values():
sum=sum+v
s=sum/len(d)
print s
print d.values()
sum = 0.0
for v in d.values():
sum=sum+v
s=sum/len(d)
print s
2015-03-18
def average(*args):
sum = 0.0
if len(args) == 0:
return 0;
else:
for a in args:
sum += a
return sum/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
sum = 0.0
if len(args) == 0:
return 0;
else:
for a in args:
sum += a
return sum/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-03-18
def greet(name='world'):
print 'Hello,'+name+'.'
greet()
greet('Bart')
留个脚印?
print 'Hello,'+name+'.'
greet()
greet('Bart')
留个脚印?
2015-03-18
import math
def quadratic_equation(a, b, c):
t = math.sqrt(b * b - 4 * a * c)
return (-b + t) / (2 * a),( -b - t )/ (2 * a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
t = math.sqrt(b * b - 4 * a * c)
return (-b + t) / (2 * a),( -b - t )/ (2 * a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2015-03-18
def square_of_sum(L):
sum = 0
for a in L:
sum += a*a
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
函数定义特别哦,oc中都是方法,-(void)sendMessage:(nsstring *)msg
sum = 0
for a in L:
sum += a*a
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
函数定义特别哦,oc中都是方法,-(void)sendMessage:(nsstring *)msg
2015-03-18
age = 20 if age >= 6 and age<=18: age="">= 6 and <=18) print="" elif="" age="">= 18: print 'adult' else: print 'kid' 编辑器推荐PyCharm,缩进什么的都他帮你弄
2015-03-17
def square_of_sum(L):
sum = 0
for lv in L:
sum = sum + (lv*lv)
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum = 0
for lv in L:
sum = sum + (lv*lv)
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-03-17